How to get the nth row from data frame in R How to get the nth row from data frame in R r r

How to get the nth row from data frame in R


You just need to use the square brackets to index your dataframe. A dataframe has two dimensions (rows and columns), so the square brackets will need to contain two pieces of information: row 10, and all columns. You indicate all columns by not putting anything. So your code would be this:

dataFrame[10,]


You can also use "slice" function in the following way:

library(dplyr)slice(dataFrame, 10)

See details here slice: Select rows by position


You can get the number of rows using nrow and then find the nth row.

dataFrame[nrow(dataFrame),]