You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using alldata <- data.table(1)[,:=(c("va", "vb", "vc", "vd"),NA)][,V1:=NULL][.0]
or alldata <- data.table(1)[,:=(c("va", "vb", "vc", "vd"),NA)][,V1:=NULL][!is.na(va)]
creates an empty data.table with 4 named columns, which I intend to iteratively append to with the results of an fread (stored in filedata). You can dummy up a value for filedata with filedata <- data.table(1)[,:=(va="bob", vb="barbara ann", vc=4, vd=as.Date("1965-09-23"), V1=NULL)]
alldata[,lapply(.SD,class)] # 0-row data seeded with NA in each column
va vb vc vd
1: logical logical logical logical
filedata[,lapply(.SD,class)] # lines of real data that you are trying to merge
va vb vc vd
1: character character integer Date
rbindlist(list(alldata,filedata))
Error in rbindlist(list(alldata, filedata), use.names = FALSE) :
Class attribute on column 4 of item 2 does not match with column 4 of item 1.
Basically, a logical column can't be auto-recast to a Date data type. Nor is IDate class data allowed to be appended to the vd column of filedata (code and results not shown here).
the Date class itself appears to accept NA as a value, but this NA appears to be slightly different from a logical NA filedata <- data.table(1)[,:=(va="bob", vb="barbara ann", vc=4, vd=as.Date(NA))][,V1:=NULL] filedata
va vb vc vd
1: bob barbara ann 4 <NA>
filedata[,lapply(.SD, class)]
va vb vc vd
1: character character numeric Date
rbindlist(list(alldata,filedata))
Error in rbindlist(list(alldata, filedata)) :
Class attribute on column 4 of item 2 does not match with column 4 of item 1.
using data.table 1.14.0 built under R version 3.6.3 in RStudio Version 1.1.463 session using R version 3.6.0
slightly modified and greatly expanded from https://stackoverflow.com/a/54081089/4228193
using
alldata <- data.table(1)[,
:=(c("va", "vb", "vc", "vd"),NA)][,V1:=NULL][.0]
or
alldata <- data.table(1)[,
:=(c("va", "vb", "vc", "vd"),NA)][,V1:=NULL][!is.na(va)]
creates an empty data.table with 4 named columns, which I intend to iteratively append to with the results of an fread (stored in
filedata
). You can dummy up a value for filedata withfiledata <- data.table(1)[,
:=(va="bob", vb="barbara ann", vc=4, vd=as.Date("1965-09-23"), V1=NULL)]
alldata[,lapply(.SD,class)] # 0-row data seeded with NA in each column
filedata[,lapply(.SD,class)] # lines of real data that you are trying to merge
rbindlist(list(alldata,filedata))
Basically, a logical column can't be auto-recast to a Date data type. Nor is IDate class data allowed to be appended to the vd column of filedata (code and results not shown here).
the Date class itself appears to accept NA as a value, but this NA appears to be slightly different from a logical NA
filedata <- data.table(1)[,
:=(va="bob", vb="barbara ann", vc=4, vd=as.Date(NA))][,V1:=NULL]
filedata
filedata[,lapply(.SD, class)]
rbindlist(list(alldata,filedata))
filedata <- data.table(1)[,
:=(va="bob", vb="barbara ann", vc=4, vd=as.logical(NA))][,V1:=NULL]
filedata[,lapply(.SD, class)]
rbindlist(list(alldata,filedata)) # note the lack of <> brackets around NA
...but it seems you can convert from a logical to a Date with explicit casting outside of data.table...
as.integer(as.logical(NA))
as.character(as.logical(NA))
as.Date(as.logical(NA))
class(as.Date(as.logical(NA)))
The text was updated successfully, but these errors were encountered: