本文介绍了如何连接向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试生成一个变量,该变量是两个字符的串联,例如从 p30s4, p28s4到 p30s4 p28s4。我尝试过猫和粘贴,如下所示。两者都返回空变量。我在做什么错了?
I'm trying to produce a single variable which is a concatenation of two chars e.g to go from "p30s4" "p28s4" to "p30s4 p28s4". I've tried cat and paste as shown below. Both return empty variables. What am I doing wrong?
> blah = c("p30s4","p28s4")
> blah
[1] "p30s4" "p28s4"
> foo = cat(blah)
p30s4 p28s4
> foo
NULL
> foo = paste(cat(blah))
p30s4 p28s4
> foo
character(0)
推荐答案
尝试使用:
> paste(blah, collapse = "")
[1] "p30s4p28s4"
您想要在它们之间留出空格:
or if you want the space in between:
> paste(blah, collapse = " ")
[1] "p30s4 p28s4"
这篇关于如何连接向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!