[R] subset by multiple columns satisfying the same condition
Peter McMahan
peter.mcmahan at gmail.com
Sun Mar 18 19:56:47 CET 2007
say x is you rdata frame and y is the vector of column indices you
want to match to a condition:
x[apply(x[y]=="Tom",1,all),]
still, i feel like there's probably a better way...
On Mar 18, 2007, at 1:36 PM, Frank Duan wrote:
> Hi All,
>
> I have a very simple question. Suppose I had a data frame with 100
> columns,
> now I wanted to select rows with the values of some columns
> satisfying the
> same condition, like all equal to "Tom". I know I can use the 'and'
> operator
> "&", but it's painful if there were many columns.
>
> Can anyone give me some advice? Thanks in advance,
>
> FD
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
More information about the R-help
mailing list