- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to access the last value in a vector in R?
This can be done by using tail function.
Example
> x<-c(253,254,36,874,351,651,245,274,19,1095) > tail(x,n=1) [1] 1095 > data <- data.frame(Class=c("Highschool","Highschool","Graduate","Graduate", "Graduate","Graduate","Masters","Masters","Masters","PhD")) > tail(data,n=1) Class 10 PhD df = data.frame(matrix(rnorm(20), nrow=5)) > tail(df,n=1) X1 X2 X3 X4 5 -0.3595053 0.9943738 0.959761 -0.6565688 > tail(df$X4,n=1) [1] -0.6565688
- Related Articles
- How to remove some last elements of a vector in R?
- How to replace a value in an R vector?
- How to remove only last character from a string vector in R?
- How to remove a particular value from a vector in R?
- How to find the index of the last occurrence of repeated values in a vector in R?
- How to check if a vector contains a given value in R?
- How to extract the maximum value from named vector in R?
- How to find minimum value in a numerical vector which is written as a character vector in R?
- How to set a specific value for a range in an R vector?
- How to find the quartile for each value in an R vector?
- How to find the position of a non-NA value in an R vector?
- Python - How to access the last element in a Pandas series?
- How to reverse a vector in R?
- How to extract the last value of all elements of a list in R?
- How to convert unit of measurements of a value or a vector in R?

Advertisements