22

For example, I have the following data frame:

> dataFrame <- read.csv(file="data.csv")
> dataFrame
    Ozone Solar.R Wind Temp Month Day
1      41     190  7.4   67     5   1
2      36     118  8.0   72     5   2
3      12     149 12.6   74     5   3
4      18     313 11.5   62     5   4
5      NA      NA 14.3   56     5   5
6      28      NA 14.9   66     5   6
7      23     299  8.6   65     5   7
8      19      99 13.8   59     5   8
9       8      19 20.1   61     5   9
10     NA     194  8.6   69     5  10

How can I get the nth row ? For example, the 10th

10     NA     194  8.6   69     5  10
maksadbek
  • 1,508
  • 2
  • 15
  • 28

3 Answers3

19

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,]
gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
4

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

library(dplyr)
slice(dataFrame, 10)

See details here slice: Select rows by position

Andrii
  • 2,843
  • 27
  • 33
0

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

dataFrame[nrow(dataFrame),]