[datatable-help] proper way to do 'ifelse' on a data table

Zachary Mayer zach.mayer at gmail.com
Wed Aug 3 23:13:20 CEST 2011


Hello,
I want to construct a new column in a data.table, based on a simple
ifelse() statement from one of the old columns.  Is there a 'proper'
way to do this, or will the simple ifelse() statement make use of
data.table's features, such as indexing?
example:

library(data.table)
DT = data.table(x=rep(c("a","b","c"),each=3),y=c(1,3,6), v=1:9)
DT$u <- ifelse(DT$y>3,1,0)
DT

Thank you,

Zach


More information about the datatable-help mailing list