r - Why does read.csv() sometimes get errors when specifying colClasses as "character"? -
i using read.csv()
make data.table
. when importing columns, need them imported either 'character' or 'numeric'.
i'm using following code (simplified brevity):
datacols <- c(a="character", b="character", c="numeric", d="character") data <- data.table(read.csv(file="data.csv", row-names=1, stringsasfactors=f, colclasses=datacols))
for ease, have datacols vector list of possible columns i'm reading number of csv files represent data @ various parts of process (which code meant checking equality).
if use above code read csv file has columns a, b, c , d reads okay. if, however, try read csv has columns a-c, following error:
error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got '"abc"'
where "abc" contents of row 1 in column b.
i'm telling read column character, , it's getting character, it's giving me error. why this? frustratingly, when doing different thing other day, if put colclasses in gave me warning said 'there more colclasses listed exist in csv'.
i'm @ loss why these errors a) different and, in case of problem described above, appearing in first place.
Comments
Post a Comment