Yi.
Yi.

Reputation: 525

How to convert a numeric vector to a string in R?

I need to convert a numeric vector to a string, for example,

c(1,0,3,4,5)

into

"10345"

Any ideas?

Upvotes: 3

Views: 4183

Answers (2)

Mayou
Mayou

Reputation: 8818

do.call(paste0,as.list(x))

The good thing about this method is that it would work with any other function, not only paste().

Upvotes: 1

Didzis Elferts
Didzis Elferts

Reputation: 98419

You can do it with function paste() and argument collapse="".

x<-c(1,0,3,4,5)
paste(x,collapse="")
[1] "10345"

Upvotes: 8

Related Questions