【问题标题】:Grouping One column's all values in one list on basis of some other column in r根据 r 中的其他列对一个列表中的一列的所有值进行分组
【发布时间】:2021-12-17 19:15:52
【问题描述】:

在这里,我想根据ticker 列对cont_name 列中的所有值进行分组。

例如下面的数据集:-

我希望输出是这样的:-

如您所见,cont_name 列的值已通过ticker 上的分组附加

【问题讨论】:

标签: r dplyr group-by grouping


【解决方案1】:

我同意 cmets 中的 dario,但使用 group_bypaste 很容易解决:

library(tidyverse)

cont <- tibble(
  ticker = c(rep('000001-SHE', 6), '000002-SHE', rep('000046-SHE', 2)), 
  cont_name = c('Bribery and Corruption', 'Business Ethics', 'Corporate Governance', 'Quality and Safety', 'Social Impacts of Products', 'Carbon Impacts of Products', 'Quality and Safety', 'Business Ethics', 'Labour Relations')
)

cont %>%
  group_by(ticker) %>%
  summarize(cont_name = paste(cont_name, collapse = ','))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多