I am attempting to exclusively use piping to rewrite the following code (using babynames data from babynames package:
library(babynames)
library(dplyr)
myDF <- babynames %>%
group_by(year) %>%
summarise(totalBirthsPerYear = sum(n))
slice(myDF, seq(1, nrow(myDF), by = 20))
The closest I have gotten is this code (not working):
myDF <- babyNames %>%
group_by(year) %>%
summarise(totalBirthsPerYear = sum(n)) %>%
slice( XXX, seq(1, nrow(XXX), by = 20))
where XXX is meant to be passed via pipes to slice, but I'm stuck. Any help is appreciated.
slice(seq(1, nrow(.), by = 20))
. You don't need the firstXXX
because the output ofsummarise
is already automatically piped intoslice
. The secondXXX
is replaced by.
, where.
is the "pronoun" used to refer to the data frame that was piped into the function. – Diaphony