adl*_*adl 1 r list vector character dplyr
我正在尝试将列表转换为单个字符值,或者基本上是从此开始:
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))
Run Code Online (Sandbox Code Playgroud)
对此:
test <- data.frame(a = c(1,2), b = c("a, b, c", "d, e, f" ))
Run Code Online (Sandbox Code Playgroud)
干得好:
test %>%
mutate(b = sapply(b, toString))
## A tibble: 2 x 2
# a b
# <dbl> <chr>
#1 1. a, b, c
#2 2. d, e, f
Run Code Online (Sandbox Code Playgroud)