根据 r 中的其他列对一个列表中的一列的所有值进行分组
Grouping One column's all values in one list on basis of some other column in r
在这里,我想根据列 ticker
对列 cont_name
中的所有值进行分组。
例如下面的数据集:-
我希望输出如下:-
如您所见,cont_name
列的值已通过分组附加到 ticker
我同意达里奥在评论中的观点,但使用 group_by
和 paste
很容易解决:
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 = ','))
在这里,我想根据列 ticker
对列 cont_name
中的所有值进行分组。
例如下面的数据集:-
我希望输出如下:-
如您所见,cont_name
列的值已通过分组附加到 ticker
我同意达里奥在评论中的观点,但使用 group_by
和 paste
很容易解决:
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 = ','))