如何按组计算所有变量的标准误差
我有数据帧包含变量:
Group high weigh age col5
row1 A 12 57 18 AA
row2 C 22 80 29 BB
row3 B 17 70 20 CC
row4 A 13 60 26 DD
row5 D 19 69 25 AA
row6 B 10 15 19 BB
row7 C 20 66 22 CC
row8 D 13 53 18 DD
我想使用package plotrix的函数std.err或使用其他方法(例如直接计算所有量化的sqrt(length(data [,columt lintar])),该组对组中的所有量化错误都在(例如((例如)第一列),所以我想要的结果是
Group se_high se_weigh se_age
row1 A 0.223 0.023 0.1
row3 B 0.12 0.1 0.12
row7 C 0.1 0.04 0.09
row8 D 0.05 0.12 0.07
我尝试使用group_by dplyr fubction进行组第一列,然后使用std.error,但我不知道如何组合它们
#this is the dplyr function to calculate the mean by group
library(dplyr)
data %>%
group_by(group) %>%
summarise_at(vars("A", "B", "C","D"), mean)
,我也想知道如何通过两组(例如,第1列和最后一栏)
谢谢
I have dataframe contain variables :
Group high weigh age col5
row1 A 12 57 18 AA
row2 C 22 80 29 BB
row3 B 17 70 20 CC
row4 A 13 60 26 DD
row5 D 19 69 25 AA
row6 B 10 15 19 BB
row7 C 20 66 22 CC
row8 D 13 53 18 DD
i want to calulate standar error using the function std.error from package plotrix or using other method ( like calculating directly sd/sqrt(length(data[,column])) of all quantitative error by group in (first column), so the result i want is
Group se_high se_weigh se_age
row1 A 0.223 0.023 0.1
row3 B 0.12 0.1 0.12
row7 C 0.1 0.04 0.09
row8 D 0.05 0.12 0.07
i tried to use group_by dplyr fubction to group column one and then use std.error but i don't know how to combine them
#this is the dplyr function to calculate the mean by group
library(dplyr)
data %>%
group_by(group) %>%
summarise_at(vars("A", "B", "C","D"), mean)
i also would like to know how to calculate std.error by two groups ( column 1 and last column 5 for example )
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你很近!摘要_AT实际上现在已弃用,所以我要做的是:
返回
You were close! Summarize_at is actually deprecated now so here's what I'd do:
which returns
这是一个一口气的解决方案:
Here is a solution to do it in one go: