QUESTION: Is there a way to reference the original dataset OR (preferably) the dataset from the chain, right before the group_by()
at all?
nrow(mtcars)
32 (but we all knew that)
> mtcars %>% group_by(cyl) %>% summarise(count = n())
# A tibble: 3 x 2
cyl count
<dbl> <int>
1 4 11
2 6 7
3 8 14
Great.
mtcars %>%
group_by(cyl) %>%
summarise(count = n(),
prop = n()/SOMETHING)
I understand I could put nrow(mtcars)
in there, but this is just a MRE. That's not an option in more complex chain of operations.
Edit: I oversimplified the MRE. I am aware of the "." but I actually wanted to be able to pass the interim tibble off to another function (within the call to summarise), so the assign solution below does exactly what I was after. Thanks.