Hello,
I'm trying to replicate a pivot table.So, I am using dplyr and group_by.
The code below , I think, collapses the sum of "hp" aggregating by "cyl" and "mpg". Also, It provides the percentage of each row.
kk=datasets::mtcars
names(kk)
kk
kk %>% group_by(cyl,mpg) %>%
summarise(st_=sum(hp)) %>%
mutate(s_st=st_/sum(st_)*100)
However, If I want to recreate the same table, but separating/splitting the analysis using "am" , I receive this:
kk %>% group_by(cyl,mpg) %>%
summarise(st_=sum(hp)) %>%
mutate(s_st=st_/sum(st_)*100) %>% group_split(am)
Warning message:
... is ignored in group_split(<grouped_df>), please use group_by(..., .add = TRUE) %>% group_split()
I don't know what am I doing wrong. Can you guide me?
Thanks for your help.