Display the position of a given value in a vector in the R

2

I started studying R in a short time and I have studied this language a lot. However, I'm having trouble getting the position of a vector, ie the order in which a certain value is written to that vector.

Eg: > vector

asked by anonymous 22.10.2017 / 00:55

1 answer

3

The first way to get the position of a given element of a vector is by using the function match as follows match(c(15, 53), vetor) . This will return the position of the elements of the vector that you consider known.

The second form is by using the function which as follows which(vetor %in% c(23, 53)) .

For knowledge purposes, if you want to know the vector element based on a given position, you can use the command vetor[3] , where 3 represents the third position. The result will be the element of the third position which in this case is 32.

    
22.10.2017 / 01:35