data.table - How to assign column names with fread in R? -
i have following code -
zz3 <- 'data,key "va1,va2,20140524,,0,0,5969,20140523134902,s7,s1147,140,20140523134902,m/t",4503632376496128 "va2,va3,20140711,,0,0,8824,20140601095714,s1,s6402,175,20140601095839,m/t",4503643113914368 "va1,va3,20140710,,0,0,11678,20140604085203,s1,s1430,250,20140604085329,m/t",4503666467799040 "va2,va1,20140724,,0,0,7109,20140523133835,s7,s793,130,20140523133835,m/t",4503679218483200 "va3,va1,20140925,,0,0,10592,20140604092548,s7,s109,395,20140604092714,m/t",4503694653521920' columnclasses <- c("or"="factor", "d"="factor", "ddate"="factor", "rdate"="factor", "changes"="integer", "class"="factor", "price"="integer", "fdate"="factor", "company"="factor", "number"="factor", "dur"="integer", "added"="factor", "source"="factor", "key"="null") # skip last column "key" data <- fread(zz3, header = false, sep = ",", skip = 1, na.strings = c(""), colclasses = columnclasses)
but returns error -
error in fread(zz3, header = false, sep = ",", skip = 1, na.strings = c(""), : column name 'or' in colclasses[[1]] not found
i expected colclasses
assigns column names, when header = false
, looks not case.
how should fix that? similar read.csv
code worked well.
it indeed not case.
colclasses
enables define column types using fread
. suppose have file splitted |
column named 'key' , want character, run command: fread(filepath, sep='|', colclasses=c(key='character'))
.
if have no names in file can use setnames
assign column names data.table
once read.
Comments
Post a Comment