通过治疗来减少许多列

发布于 2025-01-27 05:24:54 字数 844 浏览 4 评论 0原文

我有一个很大的数据集,其中包含许多列,我正在尝试找到每个处理的每一列的平均值和ST。

示例数据

治疗年龄经验等级指数
A21340,7
A24440,5
B321250,6
B542330,7
C15140,9
C19350,4

我尝试过:

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

有没有办法总结所有列而不单独添加它们? (我的数据集有56列)

谢谢您的帮助

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

treatmentageexperiencegradeindex
a21340,7
a24440,5
b321250,6
b542330,7
c15140,9
c19350,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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左秋 2025-02-03 05:24:54
df %>%
  group_by(treatment) %>%
  summarise(across(1:3, 
                ~sd(.), .names = '{col}_sd'),
            across(1:3, 
                ~mean(.), .names = '{col}_mean'))
df %>%
  group_by(treatment) %>%
  summarise(across(1:3, 
                ~sd(.), .names = '{col}_sd'),
            across(1:3, 
                ~mean(.), .names = '{col}_mean'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文