Reputation: 101
I have the following list in R, and I'm trying to extract all values from A$a that are greater than 3 using which(). I've tried the following:
A = list(a = c(2:5), b = c(3:5), c = c(4:6))
which(A$a > 3)
For some reason, it returns a vector of 3 and 4, and it excludes 5. How can I make which() return all values in A$a that are greater than 3?
Upvotes: 0
Views: 62
Reputation: 57696
3 and 4 means the 3rd and 4th elements of A$a
are greater than 3. The 3rd and 4th elements of A$a
are 4
and 5
.
If you want the elements themselves:
A$a[which(A$a > 3)]
Or just
A$a[A$a > 3]
Upvotes: 5