粘贴的替代功能 [英] Alternative function to paste
本文介绍了粘贴的替代功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可以替代粘贴的功能?
我想知道在R中是否存在这样的情况:
Is there a function that can be an alternative to paste ? I would like to know if something like this exists in R:
> buildString ( "Hi {1}, Have a very nice {2} ! " , c("Tom", "day") )
推荐答案
frankc和DWin是正确的,可以指向
sprintf()
。如果由于某种原因,您的替换零件实际上将以矢量的形式出现(即 c(Tom,day)) / code>),您可以使用 do.call()
将它们传递给 sprintf()
:
If for some reason your replacement parts really will be in the form of a vector (i.e. c("Tom", "day")
), you can use do.call()
to pass them in to sprintf()
:
string <- "Hi %s, Have a really nice %s!"
vals <- c("Tom", "day")
do.call(sprintf, as.list(c(string, vals)))
# [1] "Hi Tom, Have a really nice day!"
这篇关于粘贴的替代功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文