将字符值粘贴到 R 中打印消息前面的字符串中
Pasting character values in a character string in front of a print message in R
我在打印消息前粘贴字符串时遇到问题。具体来说,我有: > notinld
[1] "b3" "b2"
作为要粘贴在打印消息前面的字符值。
我有以下代码和结果:
> print(paste(notinld,"have not been included in the analysis due to all participants at this node for these items answering essentially the same",sep=" ",collapse=""))
[1] "b3 have not been included in the analysis due to all participants at this node for these items answering essentially the sameb2 have not been included in the analysis due to all participants at this node for these items answering essentially the same"
我不确定为什么 b2 会这样出现在消息的中间,我希望 'notinld' 中的任何字符值出现在打印消息的前面,它们之间有一个逗号这样如:
b2,b2 "print message"
谢谢!
我会在这里使用 sprintf
:
sprintf("%s have not been included", paste(notinld, collapse = ", "))
#"b3, b2 have not been included"
我在打印消息前粘贴字符串时遇到问题。具体来说,我有: > notinld
[1] "b3" "b2"
作为要粘贴在打印消息前面的字符值。
我有以下代码和结果:
> print(paste(notinld,"have not been included in the analysis due to all participants at this node for these items answering essentially the same",sep=" ",collapse=""))
[1] "b3 have not been included in the analysis due to all participants at this node for these items answering essentially the sameb2 have not been included in the analysis due to all participants at this node for these items answering essentially the same"
我不确定为什么 b2 会这样出现在消息的中间,我希望 'notinld' 中的任何字符值出现在打印消息的前面,它们之间有一个逗号这样如:
b2,b2 "print message"
谢谢!
我会在这里使用 sprintf
:
sprintf("%s have not been included", paste(notinld, collapse = ", "))
#"b3, b2 have not been included"