[datatable-help] Selecting rows that don't match

Ben Goldstein ben.goldstein at gmail.com
Sat Aug 20 02:17:06 CEST 2011


Sorry for the double post. But on the same topic, in more general sense, how
does one select rows based off of any logical?

For example:

DF = data.frame(x=1:3,y=4:6,z=7:9)
ds <- 1
new.DF <- DF[which(DF$x > ds),]

Thanks,

Ben

On Fri, Aug 19, 2011 at 4:57 PM, Ben Goldstein <ben.goldstein at gmail.com>wrote:

> Hello All,
>
> I just started using data.table and like some of the features. I apologize
> if this is a basic question, but I can't find it posted on the list. I want
> to select the rows that don't match a key.
>
> For example, in data.frame i'd do:
>
> DF = data.frame(x=1:3,y=4:6,z=7:9)
> ds <- c(1,2)
> new.DF <- DF[which(! DF$x %in% ds),]
>
>  where, ds is a vector of values that I don't want matched. So, new.DF
> would just consist of the third row.
>
> How do I do something comparable with data.table?
>
> I have:
> DT = data.table(DF)
> setkey(DT,x)
> and then I know I can select ds, by:
> DT[ds]
> but something like:
> DT[!ds] obviously doesn't work...
>
> Thanks,
>
> Ben
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20110819/de226287/attachment.htm>


More information about the datatable-help mailing list