I'd like to do sample_n()
in dplyr, except I don't want the sampling to be random, I intend to sample every n rows.
Is there a way to do this?
For example, I want to get every 10th row of the airquality
dataset after ordering by Month
and Day
. Expected output:
Ozone Solar.R Wind Temp Month Day
NA 194 8.6 69 5 10
11 44 9.7 62 5 20
115 223 5.7 79 5 30
71 291 13.8 90 6 9
12 120 11.5 73 6 19
NA 31 14.9 77 6 29
...
You would really want to be subsetting using a sequence.
mtcars[seq(1, nrow(mtcars), 10), ]
Replace both
mtcars
occurances with your data.frame, And replace10
with the nth row you want to extract