Data load error in R

Asked

Viewed 665 times

2

I’m learning to play R, and I was writing a script and all of a sudden I typed

read.csv2.ffdf(file="DM_ALUNO.csv",sep="|",first.rows=100000) 

pressed Ctrl+r and appeared the error below

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  scan() expected 'a logical', got '84312'

Someone knows what to do to solve ?

  • 2

    It is not possible to say for sure without the data, but it seems to me that you have to define the parameter colClasses manually.

  • and how I do it ?

1 answer

1

Your problem is that the function read.csv2 uses the function scan(), which requires you to define which column classes of the file you are importing. You have two options, the first, which I recommend, is that you use another function for reading.

The function I use by default for large files is the read_csv() package ("readr").

If you want to continue with this function you can define the classes with the argument colClasses=v, which v is an array with the classes of all the columns of the file you are reading.

Example: if you have 5 columns in your file, the first as text and the other numeric

read.csv2.ffdf(
    file="DM_ALUNO.csv",
    sep="|",
    first.rows=100000,
    colClasses=c("character",rep("numeric",4))        
)     

Question in English reported

Browser other questions tagged

You are not signed in. Login or sign up in order to post.