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?
To convert elements of a Vector to Strings in R, use the toString() function. The toString() is an inbuilt R function used to produce a single character string describing an R object.
There are two methods to create a vector with repeated values in R but both of them have different approaches, first one is by repeating each element of the vector and the second repeats the elements by a specified number of times. Both of these methods use rep function to create the vectors.
Using rep() function It creates a vector with the value x repeated t times. To create a vector of ones, pass 1 as the first argument to the rep() function and the length of the vector as its second argument.
Note that splitting into single characters can be done via split = character(0) or split = "" ; the two are equivalent.
Use the collapse
argument to paste
:
paste(a,collapse=" ")
[1] "aa bb cc"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With