连接字符串/字符的向量 [英] Concatenate a vector of strings/character

查看:78
本文介绍了连接字符串/字符的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个character类型的向量,如何将这些值连接成字符串?这就是我使用 paste()

If I have a vector of type character, how can I concatenate the values into string? Here's how I would do it with paste():

sdata = c('a', 'b', 'c')
paste(sdata[1], sdata[2], sdata[3], sep ='')

产生"abc".

但是,当然,只有在我提前知道 sdata 的长度的情况下,这种方法才有效.

But of course, that only works if I know the length of sdata ahead of time.

推荐答案

尝试在粘贴函数中使用空的折叠参数:

Try using an empty collapse argument within the paste function:

paste(sdata, collapse = '')

感谢 http://twitter.com/onelinetips/status/7491806343

这篇关于连接字符串/字符的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆