我正在寻找一种方法来计算两次重复中每种治疗的权重的均值,sd和se值。
Treatment Rep Weight
Line 1 1 NA
Line 1 1 NA
Line 1 1 NA
Line 1 1 NA
Line 2 1 26
Line 2 1 26
Line 2 1 26
Line 2 1 27
Line 1 2 26
Line 1 2 28
Line 1 2 26
Line 1 2 25
Line 2 2 24
Line 2 2 26
Line 2 2 25
Line 2 2 NA
我尝试了dplyr软件包,但它给出了每个复制的平均处理量,而不是两个复制的总和。
Data1 %>% group_by(Treatment, Rep) %>% summarise_at(vars(-group_cols()), list(mean = ~mean(Weight, na.rm = TRUE),
sd = ~sd(Weight, na.rm = TRUE), se= ~sd(Weight, na.rm = TRUE)/sqrt(n())))
谢谢您的帮助!
答案 0 :(得分:2)
基于OP的代码
df1 %>%
group_by(Treatment, Rep) %>%
summarise_at(vars(-group_cols()), list(mean = ~mean(Weight, na.rm = TRUE),
sd = ~sd(Weight, na.rm = TRUE),
se= ~sd(Weight, na.rm = TRUE)/sqrt(n()))) %>%
summarise_at(vars(mean:se), mean, na.rm = TRUE)
df1 <- structure(list(Treatment = c("Line 1", "Line 1", "Line 1", "Line 1",
"Line 2", "Line 2", "Line 2", "Line 2", "Line 1", "Line 1", "Line 1",
"Line 1", "Line 2", "Line 2", "Line 2", "Line 2"), Rep = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
Weight = c(NA, NA, NA, NA, 26L, 26L, 26L, 27L, 26L, 28L,
26L, 25L, 24L, 26L, 25L, NA)), class = "data.frame", row.names = c(NA,
-16L))