Issue with importing csv file

Hi! A newbie to R here (just started today).

I downloaded a csv file from the Japanese government's statistic bureau (the content is in English) and tried to import it to RStudio.

The way I did it was from Environment > Import Dataset > From Text (base)

The problem is that the column headings became weird. For example, there were weird symbols in front of the first column heading "Time", and a "." was added in empty spaces for other column headings. (See picture at the bottom)

At first I tried uploading the csv file, but encountered something like "last line missing"(?) error? So I opted to open the csv file with Notepad (I'm a Windows user), and checked that there is an extra line at the bottom of the data, and further checked that the encoding is UTF-8 with BOM.

From the picture, you can see that I chose the "Encoding" as UTF-8 because that's the closest... I can't wrap my head around what encoding is, so I guess that might be the cause?

Edit: I figured it out!
Somehow when I import it using read.csv the problem would appear, but when I import it from "environment" it would be normal. sorry for being dumb :sob: :sob: :sob:

When you encoding option make “automatic”, problem will solved.

Or you can import dataset as on photo.
Then changed the col name. This makes you earn time.

Import it and, run this:
colnames(test)[1]<-“Time”

There's a way to do it without the going through the interactive GUI in the IDE

Can you try if running that code with your file works, or if you can find the "UTF-8-BOM" encoding in IDE dropdown menu?

1 Like

Thanks for the suggestion!!

I tried automatic too, but it still turned out weird.

Previously when I was importing the csv file using read.csv the problem would appear, but when I import from "environment" it would be normal.

I don't know why, but at least it worked out!

Thanks again!

Thanks for the suggestion!!

There isn't UTF-8-BOM in the dropdown menu, I was hoping for that as well.

But I found a way to solve the issue. I don't know why it works, but at least it does!! Haha

Thanks again!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.