stevensanderson, 🔍 How to Extract Last Row in Data Frame in R
Base R
Use nrow(my_df) to get the total rows.
Extract the last row with indexing: my_df[nrow(my_df), ].dplyr
Use tail(my_df, 1) to get the last row.data.table
Convert to data.table: my_dt <- as.data.table(my_df).
Get last row using .N: my_dt[.N].Now you know three ways to extract the last row. Try it yourself! 📊
#RProgramming #DataFrames #CodingTips #R #RStats #Programming #Coding #Data #datatable #dplyr #baseR
Post: https://www.spsanderson.com/steveondata/posts/2024-04-18/
Add comment