i

R Programming Complete Tutorial

R Vector Indexing

With the help of vector indexing, we can access the vector elements. Indexing denotes the location where the values are located in a vector. This indexing may be performed using integer, character, or logic. In R index starts from 1.

We have assigned a vector of 5 elements. Index of 1 will be the first element, which is 0. Index of 2 will be the second element of the vector, which is 2. When we use x [2], it will display 2 as it is the second element of x vector.

we have mentioned more examples in the following table: