r-list list列到字符向量,其中列表是字符

时间:2018-05-04 12:00:08

标签: r list vector dplyr character

我试图将列表转换为单个字符值,或者基本上是这样:

test <- data.frame(a = c(1,1,1,2,2,2), b = c("a", "b", "c", "d", "e", "f" )) %>% 
  group_by(a) %>% summarise(b = list(b))

到此:

test <- data.frame(a = c(1,2), b = c("a, b, c", "d, e, f" )) 

2 个答案:

答案 0 :(得分:4)

你走了:

public MappingProfile()
{
    CreateMap<Location, Location>();
    CreateMap<User, UserModel>()
        .ReverseMap();
}

答案 1 :(得分:1)

根据OP的建议,我发表评论作为未来参考的答案。

从原始数据框开始,您可以执行以下操作:

data.frame(a = c(1,1,1,2,2,2), b = c("a", "b", "c", "d", "e", "f")) %>% 
   group_by(a) %>%
   summarise(b = paste(b, collapse = ","))

## A tibble: 2 x 2
#      a b    
#  <dbl> <chr>
#1  1.00 a,b,c
#2  2.00 d,e,f