Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
What are vectors?
Vector operations
Indexing and filtering
13. Accessing single elements


Nicely done! What if we would like to or use only one specific element of a vector? Let's take a look at how this can be done.

The first element of the vector a <- c(8, 9, 10) can be accessed like this:


Here, a is a vector. Inside the square brackets, we specify the index position (1) of the element we would like to retrieve. R will respond by printing the value of the first element in vector a. Likewise, we can access the second element by using an index of 2, like so:


Note that some programming languages use 0 as the index position of the first element in a vector. However, R uses the index position 1 to reference the first element of a vector.


Jamie was the first to arrive at Versico. Thus, his salary is the first element in the vector named salaries. Write a line of code that will retrieve Jamie's salary.