[R] Transforming boolean subsetting into index subsetting
gunter.berton at gene.com
Sat Jun 29 02:00:59 CEST 2013
On Fri, Jun 28, 2013 at 2:58 PM, Julio Sergio <juliosergio at gmail.com> wrote:
> One of the techniques to subset, a vector for instance, is the following:
> V <- c(18, 8, 5, 41, 8, 7)
> ##  18 8 5 41 8 7
> ( I <- abs(V - 9) <= 3 )
> ##  FALSE TRUE FALSE FALSE TRUE TRUE
> ##  8 8 7
> However, sometimes we are interested in the indexes of the elements where the
> condition holds. Is there an easy way to transform the I vector into an
> indexes vector similar to: I == c(2,5,6) ?
> I know that I can traverse the I vector with a for() loop collecting the
> indexes, I just wonder if such an operation can be avoided.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
Internal Contact Info:
More information about the R-help