简体   繁体   English

如何将数字向量转换为R中的字符串?

[英]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? 有任何想法吗?

You can do it with function paste() and argument collapse="" . 你可以使用函数paste()和参数collapse=""来完成它。

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

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

这个方法的好处是它可以与任何其他函数一起使用,而不仅仅是paste()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM