-1

I´m asked to obtain the life_expectancy median per region:

Gap %>%
      group_by(region) %>%
      summarise(Median = median(life_expectancy))

But also, mean and standard deviation.

Is there another function simplier that writing all this code?

Thank you in advance!

  • 2
    Not sure what you mean, this isn't much code (I guess that's relative) and you've only calculated 1 of the 3 summary statistics you say you need – camille Nov 14 '21 at 19:42

1 Answers1

0
library(dplyr)
mtcars %>%
  group_by(cyl) %>%
  summarize(across(mpg, list(med = median, mu = mean, sigma = sd)))
# # A tibble: 3 x 4
#     cyl mpg_med mpg_mu mpg_sigma
#   <dbl>   <dbl>  <dbl>     <dbl>
# 1     4    26     26.7      4.51
# 2     6    19.7   19.7      1.45
# 3     8    15.2   15.1      2.56
r2evans
  • 141,215
  • 6
  • 77
  • 149
  • 3
    Would it be an idea to add this answer to the above suggested very much duplicate question instead? – tjebo Nov 14 '21 at 19:51