0

I have a large data set with many columns and I am trying to find the mean and st of each column per treatment.

Example data

treatment age experience grade index
a 21 3 4 0,7
a 24 4 4 0,5
b 32 12 5 0,6
b 54 23 3 0,7
c 15 1 4 0,9
c 19 3 5 0,4

I tried:

db%>%
  group_by(treatment) %>% 
  summarise(mean=mean(age),sd=sd(age), .groups = "drop") 

Is there a way to summarise all the columns without adding them individually? (my dataset has 56 columns)

Thank you for your help

1 Answers1

0
df %>%
  group_by(treatment) %>%
  summarise(across(1:3, 
                ~sd(.), .names = '{col}_sd'),
            across(1:3, 
                ~mean(.), .names = '{col}_mean'))
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34