【问题标题】:How to create a table in R from a data set by taking the average of rows? [duplicate]如何通过取行的平均值从数据集中创建 R 表? [复制]
【发布时间】:2020-11-27 06:38:15
【问题描述】:

我有这个数据

acic2

> acic2
# A tibble: 21 x 9
   PCC    V1.1  V2.2  V3.3  V4.4  V5.5  V6.6  V7.7 Vtotal
   <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>
 1 A      8.33  5.33  6     6.5   7.67   7    5.33   6.60
 2 A      8.67  4.33  6.25  7     7.5    7    5.67   6.63
 3 B      9     4.33  7     7.25  7.83   6.8  6.17   6.91
 4 C      5.17  3.33  5.25  2.75  3.17   4    4.5    4.02
 5 C      8     6     6.25  3.5   6.17   5.6  6      5.93
 6 D      6.5   5.67  7.25  5.75  5.33   6.4  4      5.84
 7 D      6     4.67  6     5.25  3.67   4.6  5      5.03
 8 E      6.5   7     6     7     4.33   5.4  5.67   5.99
 9 E      9     5.67  6.5   8     6.17   3.6  5      6.28
10 F      9.17  8     6.5   6.25  7      6.4  6.67   7.14
# ... with 11 more rows
> 

我想通过取 PCC 中具有相同字母的列的平均值来创建一个名为 acic3 的单独数据集。所以我会为每个包含每列平均分数的字母获取一行。

【问题讨论】:

  • aggregate(.~PCC, acic2, mean)??

标签: r average mean tibble


【解决方案1】:

您可以在dplyr 中group_by 和summarize(across(...))

acic3 <- acic2 %>%
   group_by(PCC) %>%
   summarize(across(starts_with("V"), mean)

【讨论】:

    猜你喜欢
    • 2021-01-05
    • 2020-12-15
    • 2019-01-13
    • 1970-01-01
    • 2015-05-06
    • 2021-03-07
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    相关资源
    最近更新 更多