UPDATE: dplyr has been updated since this question was asked and now performs as the OP wanted
I′m trying to get the second to the seventh line in a data.frame
using dplyr
.
I′m doing this:
require(dplyr)
df <- data.frame(id = 1:10, var = runif(10))
df <- df %>% filter(row_number() <= 7, row_number() >= 2)
But this throws an error.
Error in rank(x, ties.method = "first") :
argument "x" is missing, with no default
I know i could easily make:
df <- df %>% mutate(rn = row_number()) %>% filter(rn <= 7, rn >= 2)
But I would like to understand why my first try is not working.
question from:
https://stackoverflow.com/questions/25994307/filtering-data-frame-based-on-row-number 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…