Hi,
This is an R question I've had from the beginning of the semester. I would
like to be able to grab the indices of an array conditioned on some
criteria. For example, if I have
foo <- c(1,2,1,2)
foo
[1] 1 2 1 2
and I want the indices of foo where foo[i]=1; is there a simple command in R
to do that? I know I can write a function that will do it:
index <- seq(1:length(foo))
bar <- index[index*((foo==1)*1) != 0]
so that
bar
[1] 1 3
and
foo[bar]
[1] 1 1
But, am I overlooking an obvious solution built into R?
Thanks,
John.