I am trying to specify colClasses in read.csv in an attempt to speed up the reading of csv file. However, I encounter the following problem:
assuming that i have a file called “t.csv”:
"a","b"
"x","0"
Then, if I run the following in R:
data <- read.csv('t.csv' , stringsAsFactors=FALSE, check.names=FALSE , comment.char='', colClasses= c('character','numeric') )
I got this error:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
scan() expected 'a real', got '"0"'
At first I thought it was the problem with my quote. But using quote='”‘ in read.csv didn’t help.
Your second column is not
numericas it is quoted — that makes it text.So read it as text, then call
as.numeric(...)on the column. Or alter the file.