Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while reading csv file in R

Tags:

r

csv

I am having some problems in reading a csv file with R.

 x=read.csv("LorenzoFerrone.csv",header=T)

Error in make.names(col.names, unique = TRUE) : 
      invalid multibyte string at '<ff><fe>N'

I can read the file using libre office with no problems.

I can not upload the file because it is full of sensible information.

What can I do?


Setting encoding seem like the solution to the problem.

> x=read.csv("LorenzoFerrone.csv",fileEncoding = "UCS-2LE")
> x[2,1]
[1] Adriano Caruso
100 Levels:  Ada Adriano Caruso adriano diaz Adriano Diaz alberto ferrone Alexey ... Zia Tina
like image 233
Donbeo Avatar asked Aug 26 '13 12:08

Donbeo


People also ask

How do you load a csv file in R?

To load a. csv file into the current script and operate with it, use the read. csv() method in base R. The output is delivered as a data frame, with row numbers given to integers starting at 1.

How do I view csv data in R?

Reading a CSV file The CSV file to be read should be either present in the current working directory or the directory should be set accordingly using the setwd(…) command in R. The CSV file can also be read from a URL using read. csv() function.

How do I read a csv file in RStudio?

In RStudio, click on the Workspace tab, and then on “Import Dataset” -> “From text file”. A file browser will open up, locate the . csv file and click Open. You'll see a dialog that gives you a few options on the import.

How do you fix error in file file RT Cannot open the connection in R?

To fix it for the current session, use the setwd() command. Alternatively, you can specify the exact file name directly in your R code once you have set the working directory properly.


1 Answers

This will read the column names as-is and won't return any errors:

x = read.csv(check.names = F)

To remove/replace troublesome characters in column names, use this:

iconv(names(x), to = "ASCII", sub = "")
like image 189
Balamurali N.R Avatar answered Sep 21 '22 00:09

Balamurali N.R