Let's assume that I want to do something within groups, for example extract first row from each group. With tidyverse
and iris
dataset it's rather easy:
iris %>%
group_by(Species) %>%
nest() %>%
mutate(first_within_group = map(data, ~head(.x, 1))) %>%
select(-data) %>%
unnest()
However, with bigger datasets I strike on performance issues. Is there an alternative for group_by()
+ nest()
that would be more efficient in terms of speed? Is the performance dependent on number of factors inside group_by()
?