w3resource

R Programming: Access the last value in a given vector

R Programming: Vector Exercise-12 with Solution

Write a R program to access the last value in a given vector.

Sample Solution :

R Programming Code :

x = c(10, 20, 30, 20, 20, 25, 9, 26)
print("Original Vectors:")
print(x)
print("Access the last value of the said vector:")
print(tail(x, n=1))

Sample Output:

[1] "Original Vectors:"
[1] 10 20 30 20 20 25  9 26
[1] "Access the last value of the said vector:"
[1] 26                         

R Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a R program to count the specific value in a given vector.
Next: Write a R program to find second highest value in a given vector.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.