1233023
1233023

Reputation: 311

Find amount of index's before a threshold value is met

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

Answers (1)

akrun
akrun

Reputation: 886938

You can try

which.max(v1>12)

Or as @DavidArenburg commented, a faster option would be

which(v1>12)[1L]

data

v1 <- c(0,3,2,7,13,2,12,13)

Upvotes: 2

Related Questions