从数据框中获取各组的均值和标准差 [英] Getting mean and standard deviation from groups in a data.frame
本文介绍了从数据框中获取各组的均值和标准差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有列表形式的心率数据,其中四个类别1AS,1CS,1AI,1CI各自具有可变大小.我想为列表中的每个类别输出均值和标准差.我有这种格式的数据来计算ANOVA和Tukey,我已经成功完成了,但是平均值让我很困惑!
I have heart rate data in the form of a list with the four categories 1AS, 1CS, 1AI, 1CI each of variable size. I would like to output mean and standard deviations for each category in the list. I have the data in this format to calculate ANOVA and Tukey which I have done successfully but the mean has me stumped!
Group HR
1 1AS 300
2 1AS 280
3 1AS 260
4 1AS 250
5 1AS 300
6 1AS 272
7 1AS 250
8 1AS 198
9 1AS 200
10 1AS 195
11 1AS 214
12 1AS 249
13 1AS 240
14 1CS 250
15 1CS 236
16 1CS 200
17 1CS 272
18 1CS 206
19 1CS 203
20 1CS 237
21 1CS 214
22 1AI 218
23 1AI 276
24 1AI 240
25 1AI 264
26 1AI 300
27 1AI 315
28 1AI 300
29 1AI 285
30 1AI 286
31 1CI 167
32 1CI 233
33 1CI 214
34 1CI 219
35 1CI 214
36 1CI 246
37 1CI 230
38 1CI 218
推荐答案
假设您的数据位于名为DF
的data.frame中:
Assuming your data is in a data.frame called DF
:
by(DF$HR,DF$Group,mean)
# DF$Group: 1AI
# [1] 276
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
# DF$Group: 1AS
# [1] 246.7692
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
# DF$Group: 1CI
# [1] 217.625
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
# DF$Group: 1CS
# [1] 227.25
by(DF$HR,DF$Group,sd)
# DF$Group: 1AI
# [1] 30.93946
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
# DF$Group: 1AS
# [1] 36.48551
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
# DF$Group: 1CI
# [1] 23.25595
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
# DF$Group: 1CS
# [1] 25.77236
这篇关于从数据框中获取各组的均值和标准差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文