我有一个如下数据框:
case simulation temp plank oxygen
1 1 1 8 7 11
2 2 1 16 10 15
...
17 17 2 26 12 17
18 18 2 15 8 12
19 19 2 28 11 21
20 20 2 24 6 14
我想按仿真变量的级别划分摘要。例如,我想要temp
模拟== 1和模拟== 2 的平均值,以及标准偏差的平均值。
目前,我正在使用以下代码,这非常可怕:
df <- read.csv("data.csv")
attach(df)
# Create subset variables
temp1 = subset(temp, simulation==1)
temp2 = subset(temp, simulation==2)
plank1 = subset(plank, simulation==1)
plank2 = subset(plank, simulation==2)
oxygen1 = subset(oxygen, simulation==1)
oxygen2 = subset(oxygen, simulation==2)
print(sd(temp1))
print(sd(temp2))
print(sd(plank1))
print(sd(plank2))
我敢肯定,在R中必须有一种自动的方法,但是我找不到它。我尝试使用summary(df ~ simulation)
,但这不会产生任何有用的信息。