2015-06-24 25 views
0

我在粘貼打印信息前面的字符串時遇到問題。具體來說,我有:> notinld [1] "b3" "b2"作爲字符值粘貼在打印消息的前面。 我有結果下面的代碼:粘貼R中打印信息前面的字符串中的字符值

> 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" 

謝謝!

+1

運行'膏(C( 'A', 'B'),C( 'd'))',你就會明白爲什麼它的發生。 – joran

+0

...更重要的是,如文檔中所寫:「如果參數是向量,則它們按照術語連接在一起以給出一個字符向量結果。向量參數根據需要循環使用,零長度參數爲回收到「」。「 – joran

回答

1

我會在這裏使用sprintf

sprintf("%s have not been included", paste(notinld, collapse = ", ")) 
#"b3, b2 have not been included" 
+0

工作感謝你! – costebk08