adrian1121 adrian1121 - 11 months ago 51
R Question

Importing a .csv into R with UTF-8 encoding error?

I have a .csv file which is written in spanish so it has special characters like ñ, á, é, í, ó, ú. So if I open it in the notepad I can see all the characters properly written and I have already saved the file with UTF-8 encoding. However, when I open RStudio and I import the data using:

servutf <- read.csv("servutf.csv", sep=";")

I get all the dataset but incorrectly encoded i.e.:

Tengo 7 años de experiencia

It should be the following:

Tengo 7 años de experiencia

I have tried everything, I don't know what else to do as I have already checked that R is using UTF-8 encoding and the file is encoded in the same way.

Any suggestion please?

Answer Source

You need to specify the encoding

servutf <- read.csv("servutf.csv", sep=";", encoding = "UTF-8")