Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a list into a string

Tags:

r

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"
like image 698
Vinodh Velumayil Avatar asked Jun 16 '15 07:06

Vinodh Velumayil


People also ask

How do I turn a list into a string?

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.

Can we convert list to string in Java?

We use the toString() method of the list to convert the list into a string.

How do I convert a list of numbers to 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.


1 Answers

 paste( unlist(l), collapse='')
like image 56
Marcin Kosiński Avatar answered Oct 07 '22 15:10

Marcin Kosiński