【问题标题】:Mean/sd: Figure out the mean and standard deviation for each group. And then the one closer to one of the groups is assigned that平均值/标准差:计算出每组的平均值和标准差。然后分配给更接近其中一个组的那个
【发布时间】:2019-02-19 18:33:26
【问题描述】:

这是我的数据。

我正在尝试找出群组A 和群组Bmean/sd,但我不知所措:

library(ggplot2)
n <- 10000
df <- data.frame(
  cats=rep(c("A","B"), each=n), 
  vals=c(rnorm(n, mean=10, sd=2), rnorm(n, mean=20, sd=2))
)
ggplot(df, aes(vals, color=cats)) +
  geom_density()

【问题讨论】:

  • 不清楚您的期望

标签: r statistics probability


【解决方案1】:

你可以使用 dplyr::summarize

library(dplyr)
df %>% group_by(cats) %>% summarize(sd = sd(vals), mean = mean(vals))

cats     sd  mean
<fct> <dbl> <dbl>
1 A      1.99  10.0
2 B      1.98  20.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 2016-03-11
    • 2018-01-21
    • 2012-04-20
    • 1970-01-01
    相关资源
    最近更新 更多