dataFrame ...">

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

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 
+10
r dataset
source share
2 answers

You just need to use square brackets to index your frame. A data block has two dimensions (rows and columns), so the square brackets must contain two pieces of information: row 10 and all columns. You specify all columns without putting anything. So your code will be as follows:

 dataFrame[10,] 
+9
source share

You can also use the slice function as follows:

 library(dplyr) slice(dataFrame, 10) 

Details here slice: select rows by position

0
source share

All Articles