r - Convert a list of lists to a character vector -


i have list of lists of characters. example:

l <- list(list("a"),list("b"),list("c","d")) 

so can see elements lists of length > 1.

i want convert list of lists character vector, i'd lists length > 1 appear single element in character vector.

the unlist function not achieve rather:

> unlist(l) [1] "a" "b" "c" "d" 

is there faster than:

sapply(l,function(x) paste(unlist(x),collapse="")) 

to desired result:

"a"  "b"  "cd" 

you can skip unlist step. figured out paste0 needs collapse = true "bind" sequential elements of vector together:

> sapply( l, paste0, collapse="") [1] "a"  "b"  "cd" 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -