When going through a vector, is it possible to use the index of an element together with an element?
a.vector <-c ("a", "b", "c", "a", "d")
Suppose I need the index of the "first" "a" of the vector. Can not use
which (a.vector == "a")
Because there are two “a's,” and it will return two positions 1 and 4. I need a specific index of the element, which the loop instantly covers.
I need this for something like this:
b.vector <-c ("the", "cat", "chased", "a", "mouse")
for (i in a.vector) { element<-b.vector[INDEX.OF(a.vector)]) -------some process using both 'element' and "a"-------}
This is similar to the enumerate function in python. The solution will help a lot. Thanks.
source share