你可以做:
library(dplyr)
library(purrr)
df %>%
mutate(score = map_chr(score, toString))
# A tibble: 3 x 2
person score
<chr> <chr>
1 Alice Red, Green, Blue
2 Bob Orange, Green, Yellow
3 Mary Blue
如果您有多个列表列,您可以执行以下操作:
df <- tibble(person = c("Alice", "Bob", "Mary"),
score1 = list(c("Red", "Green", "Blue"), c("Orange", "Green", "Yellow"), "Blue"),
score2 = rev(list(c("Red", "Green", "Blue"), c("Orange", "Green", "Yellow"), "Blue")))
df %>%
mutate_if(is.list, ~ map_chr(.x, toString))
# A tibble: 3 x 3
person score1 score2
<chr> <chr> <chr>
1 Alice Red, Green, Blue Blue
2 Bob Orange, Green, Yellow Orange, Green, Yellow
3 Mary Blue Red, Green, Blue