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.
我正在使用xyplot输入Y1 + Y2 ~ X。我想Y1 + Y2作为一个列表传递,而不是两个显式变量。这样,我可以编写一个通用xyplot函数并为一系列 Y 传递不同的值。那可能吗?
xyplot
Y1 + Y2 ~ X
Y1 + Y2
一种策略是首先将公式的字符串表示形式粘贴在一起,然后将其转换为 class 的对象"formula",使用as.formula(). 这是一个使用mtcarsbase R 附带的数据框的示例。
"formula"
as.formula()
mtcars
Y <- c("mpg", "cyl") f <- as.formula(paste(paste(Y, collapse=" + "), " ~ disp")) lattice::xyplot(f, data = mtcars)