I would like to convert value stored as a list
into a single string.
For example:
l <- list(1,2,3,4)
would give:
"1234"
and not as using the output of unlist()
:
unlist(l)
#[1] "1" "2" "3" "4"
To convert a list to a string, use Python List Comprehension and the join() function. The list comprehension will traverse the elements one by one, and the join() method will concatenate the list's elements into a new string and return it as output.
We use the toString() method of the list to convert the list into a string.
You can convert an integer list to a string list by using the expression list(map(str, a)) combining the list() with the map() function. The latter converts each integer element to a string. The former converts the resulting iterable to a list.
paste( unlist(l), collapse='')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With