Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图通过以下方式在评估之前动态创建一个表达式:
authors <- c("John1","John2") exp1 <- "(Author1==%s & Author2==%s)"
我想得到以下字符串:
desired_output <- "(Author1==\"John1\" & Author2!=\"John2\")"
,然后可以使用 eval() 进行评估。
我试过:sprintf(exp1,authors),但这不起作用......解决方案是什么?
sprintf(exp1,authors)
你可以使用这个:
library(plyr) splat(sprintf)(c(exp1, authors))
或者没有图书馆:
do.call(sprintf,as.list(c(exp1,authors)))