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,
>   
Here's one way:
 
rowSums(myframe != "Tom") == 0

The following approach might generalize more easily, though

 do.call("pmin", lapply(myframe, "==", "Tom"))

(notice that pmin on logical vectors is TRUE, if all are TRUE, else 
FALSE or NA).

______________________________________________
[email protected] 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.

Reply via email to