Saptarshi Guha
2013-Sep-18 22:56 UTC
[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]]
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.