我有一个关于在R.一时间产生警告,多个项目,请参考下面的数据帧和代码的问题:R中警告了产生一个以上的项目
数据帧DAT:
inputs var1 var2
A 1 a 1
B 2 b 3
B 3 b NA
C 4 d NA
C 5 e 4
if (any(duplicated(dat$inputs))==T){
warning(paste("The following inputs: ", dat$inputs[duplicated(dat$inputs)],"is duplicated.",sep=""))
}
正如你可以看到B和C将在警告中显示,如:
Warning message:
The following inputs: B is duplicated.The following inputs: C is duplicated.
我可以接受这样的警告消息输出,但它并不理想。有没有办法将两个句子结合起来,使它看起来像:
Warning message:
The following inputs: B,C are duplicated.
非常感谢您的关注和时间。
海伦
看一看'sprintf'和' “%S”'部分 – 2014-09-24 17:50:54
注意'paste'会回收,以适应最长的输入。尝试'粘贴(“测试”,1:5,“再次测试”),看看会发生什么。正如Vlo指出的那样,'collapse'选项就是你要找的。 – Frank 2014-09-24 17:53:42