Reputation: 5719
How do you paste list of items and get the result as shown below?
mylist<- list(c("PDLIM5", "CBG"), c("PDLIM5", "GTA"), "DDX60")
result
PDLIM5:CBG PDLIM5:GTA DDX60
Upvotes: 5
Views: 13929
Reputation: 23014
The pipe-friendly tidyverse equivalent with a map
function from purrr
:
library(purrr)
mylist %>%
map_chr(paste, collapse = ":")
Upvotes: 2
Reputation: 24074
you can try:
sapply(mylist, paste, collapse=":")
#[1] "PDLIM5:CBG" "PDLIM5:GTA" "DDX60"
The result is a vector.
If you want to further paste the result, you can do:
paste(sapply(mylist, paste, collapse=":"), collapse=" ")
#[1] "PDLIM5:CBG PDLIM5:GTA DDX60"
Upvotes: 13