Steven Sanderson takes a slice:
Explanation: – We use
nrow(my_df)
to get the total number of rows in the data frame. – Then, we use indexing ([nrow(my_df), ]
) to extract the last row.
Read on for a simple example of getting the last row using base R, dplyr, and data.table. Then, we kick it up a notch to get the second-to-last row, with the idea being that you could substitute “second-to-last” with any arbitrary number.