On a similar theme, I find the function which() very useful. It returns the position of elements in a vector or a matrix which satisfy a certain condition.example:> x <- sample(1:20,10,replace=TRUE)> x[1] 18 4 19 1 5 16 12 7 7 18> which(x<10)[1] 2 4 5 8 9> x[which(x<10)][1] 4 1 5 7 7
On a similar theme, I find the function which() very useful. It returns the position of elements in a vector or a matrix which satisfy a certain condition.
ReplyDeleteexample:
> x <- sample(1:20,10,replace=TRUE)
> x
[1] 18 4 19 1 5 16 12 7 7 18
> which(x<10)
[1] 2 4 5 8 9
> x[which(x<10)]
[1] 4 1 5 7 7