[R] rbinlist for data.table and specifying the column class

arun smartpink111 at yahoo.com
Thu Sep 19 02:44:06 CEST 2013


Hi,
Try:

rbindlist(list(list(a=NA_integer_,b=NA),list(a=20,b=FALSE)))
#    a     b
#1: NA    NA
#2: 20 FALSE


A.K.

----- Original Message -----
From: Saptarshi Guha <saptarshi.guha at gmail.com>
To: "R-help at r-project.org" <R-help at r-project.org>
Cc: 
Sent: Wednesday, September 18, 2013 6:56 PM
Subject: [R] rbinlist for data.table and specifying the column class

hello,


This

rbindlist(list(list(a=NA,b=NA),list(a=20,b=FALSE)))

returns

      a     b
1:   NA    NA
2: TRUE FALSE

as per the documentation ?rbindlist

is there a way to specify the column class of 'a' to be numeric?
In actual usage, i wont be able to re-order the 2nd list entry to be the
first.

I did try

rbindlist(list(list(a=numeric(0),b=logical(0),list(a=NA,b=NA),list(a=20,b=FALSE)))

but got

      a     b
1:   NA    NA
2: TRUE FALSE

This worked

mu  =
rbindlist(list(list(a=numeric(1),b=logical(1),list(a=NA,b=NA),list(a=20,b=FALSE)))
mu = mu[-1,]

Is there a way to specify up front the classes rather than the last approach

Regards
Saptarshi

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list