tail

tail returns the last n (the default is 6) values of a vector, or rows of a matrix, table, data.frame or function.

Examples

How do I get the last 6 rows of a data.frame?

Click to see solution
df <- data.frame(a=c(1,2,3), b=c(4,5,6), c=c(7,8,9))
tail(df)
Result
  a b c
1 1 4 7
2 2 5 8
3 3 6 9

How do I get the last 2 rows of a data.frame?

Click to see solution
tail(df, 2)
  a b c
2 2 5 8
3 3 6 9