I have a dataset data.frame(x=rnorm(100),group=c(rep(\'a\',40),rep(\'b\',60)))
that I want to analyse per group with dplyr. For example I want to use a fft
We can do with unnest
after creating a list
output with summarise
. It would be more easier to work with
library(tidyverse)
df1 %>%
group_by(group) %>%
summarise(value = list(fft(x))) %>%
unnest()
There are essentially three options:
summarize
.mutate
.do
.The last option seems to fit your purpose best, if I understood you correctly. do
is generally the most powerful of these options, but also the hardest to use. The general syntax is:
data %>%
group_by(grouping_cols) %>%
do(data_frame(col1 = some_transformation(.$x)))
For example:
iris %>%
group_by(Species) %>%
do(broom::tidy(lm(Sepal.Length ~ Sepal.Width, data = .)))