R 分组并操作嵌套的文件
我有一些数据,我根据一些变量的分数计算了一些分位数。我使用以下代码创建嵌套的TIBLE: 代码: 这给了我:R 分组并操作嵌套的文件,r,dplyr,tidyr,R,Dplyr,Tidyr,我有一些数据,我根据一些变量的分数计算了一些分位数。我使用以下代码创建嵌套的TIBLE: 代码: 这给了我: # A tibble: 2 x 2 QM ave <int> <dbl> 1 1 0.644 2 2 0.956 #一个tible:2x2 QM大街 1 1 0.644 2 2 0.956 所以我想在数据中的所有列表上执行此操作 数据: df假设我们需要在“m_五分位”列表列上执行此操作,拉列并通过列表映射,按
# A tibble: 2 x 2
QM ave
<int> <dbl>
1 1 0.644
2 2 0.956
#一个tible:2x2
QM大街
1 1 0.644
2 2 0.956
所以我想在数据中的所有列表上执行此操作
数据:
df假设我们需要在“m_五分位”列表
列上执行此操作,拉
列并通过列表
映射
,按“QM”分组,得到“score1”的平均值
nested_results %>%
pull(m_quintile) %>%
map(~ .x %>%
group_by(QM) %>%
summarise(Ave = mean(score1)))
nested_results %>%
pull(m_quintile) %>%
bind_rows(, .id = 'grp') %>%
group_by(grp, QM) %>%
summarise(Ave = mean(score1))
或者在提取列后,
将行
绑定到一个具有标识符列(.id
)的单个数据集中,按“QM”、“grp”分组,获得“score1”的平均值
nested_results %>%
pull(m_quintile) %>%
map(~ .x %>%
group_by(QM) %>%
summarise(Ave = mean(score1)))
nested_results %>%
pull(m_quintile) %>%
bind_rows(, .id = 'grp') %>%
group_by(grp, QM) %>%
summarise(Ave = mean(score1))
假设我们需要在'm_quintile'列表
列上执行此操作,拉
列并通过列表
映射
,按'QM'分组,得到'score1'的平均值
nested_results %>%
pull(m_quintile) %>%
map(~ .x %>%
group_by(QM) %>%
summarise(Ave = mean(score1)))
nested_results %>%
pull(m_quintile) %>%
bind_rows(, .id = 'grp') %>%
group_by(grp, QM) %>%
summarise(Ave = mean(score1))
或者在提取列后,
将行
绑定到一个具有标识符列(.id
)的单个数据集中,按“QM”、“grp”分组,获得“score1”的平均值
nested_results %>%
pull(m_quintile) %>%
map(~ .x %>%
group_by(QM) %>%
summarise(Ave = mean(score1)))
nested_results %>%
pull(m_quintile) %>%
bind_rows(, .id = 'grp') %>%
group_by(grp, QM) %>%
summarise(Ave = mean(score1))