Enuma
November 23, 2020, 8:31am
1
Hello.
I wonder what is the tidyverse equivalent for this:
library(dplyr)
data("iris")
iris %>%
group_by(Species) %>%
select(Sepal.Length) %>%
do(broom::tidy(summary(.$Sepal.Length)))
This returns a nice clean df of grouped summary statistics. Works like a champ. The problem is, I stole the code somewhere on SO and I am somewhat reluctant to internalize it the way it is. Is there an elegant tidyverse solution to this, which I managed to ignore?
Thanks a lot!
your code relied on broom::tidy which you hadnt declared.
You can do this
iris %>%
group_by(Species) %>%
summarise(across(.cols = Sepal.Length,
.fns = list(min=min,
q1 = ~quantile(.,.25),
median=median,
mean=mean,
q3 = ~quantile(.,.75),
max=max),
.names ="{.fn}"))
2 Likes
Enuma
November 23, 2020, 4:17pm
3
Thanks, I edited the question. I was hoping for some more concise solution . I'll think about it some more. Thank you.
If you construct a function it can be as concise as your function name,...(or Rstudio snippet)
system
Closed
December 14, 2020, 4:25pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.