[R] subset data.frame with constraint of many values?

Dong-hyun Oh r.arecibo at gmail.com
Wed Oct 24 11:44:25 CEST 2007


Dear UseRs,

Let us assume that I have data.frame named as dt.

dt is as follows:

a    b    c    d
1    3    4    5
2    3    3    2
1    3    4    2
3    2    4    5
4    5    3    6
3    2    5    7
2    5    7    8
.....................
.....................

I want to subset dt with fileds a having 2 or 3 or 4, and I wrote  
following code.

dt[dt$a == 2 | dt$a == 3 | dt$a == 4,]

Is there more efficient way for subset?

Thanks in advance.



More information about the R-help mailing list