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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -