Hi,
You should use the logical "and", i.e., "&" to tell R
that you need
condition 1 (first column equals 1) AND condition 2 (second column
equals 1) to be true:
which(X[, 1] == 1 & X[, 2] == 1)
HTH,
Josh
On Sun, Nov 14, 2010 at 12:39 AM, gtg <maifeng at gmail.com>
wrote:>
> Hi all, I would like to get the row numbers in X where col1 and col2 are
both
> 1
> I tried this:
> which(X[,c(1,2)]==1)
> but it gives me the row numbers where either col1 or col2 = 1
>
> What should I do? Thank you.
> --
> View this message in context:
http://r.789695.n4.nabble.com/gettng-the-row-number-based-on-column-conditions-tp3041549p3041549.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/