有时我想在单个字符串中打印向量中的所有元素,但是它仍然单独打印元素:

notes <- c("do","re","mi")
print(paste("The first three notes are: ", notes,sep="\t"))


这使:

[1] "The first three notes are: \tdo" "The first three notes are: \tre"
[3] "The first three notes are: \tmi"


我真正想要的是:

The first three notes are:      do      re      mi

最佳答案

最简单的方法可能是使用一个c函数将您的消息和数据组合在一起:

paste(c("The first three notes are: ", notes), collapse=" ")
### [1] "The first three notes are:  do re mi"

关于r - 如何在R中的单个字符串中打印矢量的所有元素?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28866584/

10-12 23:15