[datatable-help] proper way to do 'ifelse' on a data table
Matthew Dowle
mdowle at mdowle.plus.com
Thu Aug 4 00:09:54 CEST 2011
Hi,
I'm not clear on the question here. Firstly because this example doesn't
use indexing. Secondly because the ifelse isn't needed at all: DT$y>3 is
already the result 1 or 0. Why would/should an ifelse make use of
indexing?
Matthew
On Wed, 2011-08-03 at 17:13 -0400, Zachary Mayer wrote:
> 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
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
More information about the datatable-help
mailing list