string 将 R 向量转换为 1 个元素的字符串向量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13973116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:45:43  来源:igfitidea点击:

Convert R vector to string vector of 1 element

stringrvectorargumentssystem

提问by Jetse

Im working with the programming language R now. I have a vector:

我现在正在使用编程语言 R。我有一个向量:

a <- c("aa", "bb", "cc")

And I want to paste these to a system command, I'm trying it this way now:

我想将这些粘贴到系统命令中,我现在正在尝试这种方式:

args <- paste(a, sep=" ")
system(paste("command",args, sep=" "))

But now I'm only getting the arguments aa, and I want the arguments aa, bb and cc...

但现在我只得到参数 aa,我想要参数 aa、bb 和 cc...

Anyone knows what I'm doing wrong?

有谁知道我做错了什么?

回答by James

Use the collapseargument to paste:

使用collapse参数paste

paste(a,collapse=" ")
[1] "aa bb cc"