On the tidyverse website reference, I saw two usage mutate(mtcars, row_number() == 1L) and mtcars %>% filter(between(row_number(), 1, 10)) . It would be straight forward to think that the row_number() function is return the row number for each observation in the dataframe.
However, it has been emphasized in the documentation that the function is a window function and is similar to sortperm in other languages. As in the example:
x <- c(5, 1, 3, 2, 2, NA) row_number(x)
which yields to: c( 5 1 4 2 3 NA )
May I ask if this function is intended to report the row number for each observations? If it is, what is the logic flow behind the function call?
So yes it's a dplyr function, but it's simply a wrapper around the base function rank() and if you check the arguments, you can see, that e.g. row_number() == 1L will let you manipulate based on ranks, e.g.: