This function returns the location of the first, second, third (and so on) occurrence of a specified non-sequential value in a vector.

findFirst(invec, value, event)

Arguments

invec

The input vector.

value

The value you are looking for.

event

The desired position to be returned.

Value

A vector of length 1.

References

http://stackoverflow.com/q/22049035/1270695

Author

Ananda Mahto

Examples

set.seed(1) a <- sample(LETTERS[1:5], 20, TRUE) a
#> [1] "A" "D" "A" "B" "E" "C" "B" "C" "C" "A" "E" "E" "B" "B" "A" "E" "E" "A" "A" #> [20] "E"
## Note the difference between the following. ## The value "2" is skipped because it is sequential. which(a == "B")
#> [1] 4 7 13 14
findFirst(a, "B", 2)
#> [1] 7