View the Bottom Rows in R DataFrame using Tail

The tail() function can be used to view the bottom rows in R DataFrame:

tail(df, number of bottom rows needed)

For example, to view the bottom 2 rows:

# Create a sample DataFrame
df <- data.frame(product = c("computer", "monitor", "keyboard", "printer", "tablet"),
                 price = c(1200, 400, 100, 200, 300),
                 brand = c("A", "B", "C", "X", "Y")
                 )

# View the bottom two rows using tail()
print(tail(df, 2))

The result:

  product  price  brand
4 printer    200      X
5  tablet    300      Y

You may check the following guide to view the top rows in R DataFrame.

Leave a Comment