Have a character vector called error.list with multiple elements in it. I tried to include the complete vector in my paste statement as shown below:
paste("Hi, Your data has the following errors:", error.list," Regards, XYZ",
sep='').
But I am getting an error. The console says it can't add all the elements in a single paste statement. Can help me with this? is there another way to do it?
Your approach will work For inputs of length 1
but you have a vector.
Because
error.list
is avector
, use one of the following methods:
error.list <- c("a", "b", "c")
paste(c("Hi, Your data has the following errors:", error.list, " Regards, XYZ"), sep = " ")
Provide the output:
[1] "Hi, Your data has the following errors:" "a" [3] "b" "c" [5] " Regards, XYZ"
One line use parameter collapse =
:
paste(c("Hi, Your data has the following errors:", error.list, " Regards, XYZ"), sep = " ", collapse = " ")
Provide the output:
"Hi, Your data has the following errors: a b c Regards, XYZ"
or you can use
paste0()
with parametercollapse =
to get one line output, for also using theerror.list
as vector:
paste0(c("Hi, Your data has the following errors:", error.list, " Regards, XYZ"), collapse = " ")
Provide the output:
[1] "Hi, Your data has the following errors: a b c Regards, XYZ"