Reputation: 311
I have a problem in R, where I have a vector, and I want to count at which index, a threshold value is first met.
so I have like
[0,3,2,7,13,2,12,13]
and I want to know at which index, the value exceeds 12
, which would be entry nr. 5
.
Thanks!
Upvotes: 0
Views: 118
Reputation: 886938
You can try
which.max(v1>12)
Or as @DavidArenburg commented, a faster option would be
which(v1>12)[1L]
v1 <- c(0,3,2,7,13,2,12,13)
Upvotes: 2