R 使用向量粘贴文本
我正在尝试使用向量粘贴一些文本:R 使用向量粘贴文本,r,R,我正在尝试使用向量粘贴一些文本: v1 <- c(16,17,18) paste ("the numbers in v1 are:",v1) 我将非常感谢您对我所做错误的建议。您需要先折叠v1: paste("the numbers in v1 are:", paste(v1, collapse = ",")) # [1] "the numbers in v1 are: 16,17,18" 您的代码将首先重复“v1中的数字是”,直到它与v1的长度匹配,然后它将按索引将向量的元素粘贴在
v1 <- c(16,17,18)
paste ("the numbers in v1 are:",v1)
我将非常感谢您对我所做错误的建议。您需要先折叠
v1
:
paste("the numbers in v1 are:", paste(v1, collapse = ","))
# [1] "the numbers in v1 are: 16,17,18"
您的代码将首先重复“v1中的数字是”
,直到它与v1
的长度匹配,然后它将按索引将向量的元素粘贴在一起
或
不完全正确,但它实现了目标
cat("the numbers in v1 are:", v1)
sprintf('the numbers in v1 are: %s', toString(v1))
# [1] "the numbers in v1 are: 16, 17, 18"
cat("the numbers in v1 are:", v1)