Convert R vector to string vector of 1 element

116,403

Use the collapse argument to paste:

paste(a,collapse=" ")
[1] "aa bb cc"
Share:
116,403
Jetse
Author by

Jetse

Updated on July 05, 2022

Comments

  • Jetse
    Jetse almost 2 years

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

    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...

    Anyone knows what I'm doing wrong?

  • fernal73
    fernal73 about 4 years
    What if it's a named vector and I need the labels as well?