具有一个名为error.list的字符向量,其中包含多个元素。我试图在我的粘贴语句中包括完整的向量,如下所示:
paste("Hi, Your data has the following errors:", error.list," Regards, XYZ",
sep='').
但是我遇到一个错误。控制台表示无法在单个粘贴语句中添加所有元素。可以帮我吗?还有另一种方法吗?
答案 0 :(得分:1)
您的方法将For inputs of length 1
有效,但是您有一个方向。
由于
error.list
是vector
,请使用以下方法之一:
error.list <- c("a", "b", "c")
paste(c("Hi, Your data has the following errors:", error.list, " Regards, XYZ"), sep = " ")
提供输出:
[1] "Hi, Your data has the following errors:" "a" [3] "b" "c" [5] " Regards, XYZ"
一行使用参数collapse =
:
paste(c("Hi, Your data has the following errors:", error.list, " Regards, XYZ"), sep = " ", collapse = " ")
提供输出:
"Hi, Your data has the following errors: a b c Regards, XYZ"
或者您可以将
paste0()
与参数collapse =
一起使用以获取一行输出,也可以将error.list
用作向量:
paste0(c("Hi, Your data has the following errors:", error.list, " Regards, XYZ"), collapse = " ")
提供输出:
[1] "Hi, Your data has the following errors: a b c Regards, XYZ"