Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read.csv() throws error

Tags:

r

read.csv

I have been trying to read the excel file but seems like there is something wrong. The file is stored in Documents folder in excel format.

These are the error messages that I get :

table <- read.csv(file.choose(),header=T,sep='\t')

Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 

also, since these were warnings , I happened to ignore them. But nothing has been read into "table" either:

table
# [1] PK...
# <0 rows> (or 0-length row.names)
like image 521
Minal Murkhande Avatar asked Sep 16 '14 15:09

Minal Murkhande


2 Answers

read.csv doesn't read XLS(X) files, only CSV files. Try opening your Excel file in Excel, exporting it to CSV and reissuing your read.csv command (depending on your system language, you might want to use read.csv2 instead).

like image 71
Waldir Leoncio Avatar answered Sep 24 '22 12:09

Waldir Leoncio


I had a similar error, e.g:

A <- read.csv("tel.csv", sep = ",")
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  empty beginning of file
In addition: Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  invalid input found on input connection 'tel.csv'
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 'tel.csv'

For solution I tried:

A <- read.csv("tel.csv", sep = ",",
              fileEncoding="utf-16")

It worked.

like image 31
Rafa Avatar answered Sep 23 '22 12:09

Rafa