この機能を考慮してください:
tf <- function(formula = NULL, data = NULL, groups = NULL) {
grv <- eval(substitute(groups), data, environment(formula)) # the values
grn <- as.character(match.call()$groups) # the name
gr <- match.call()$groups # unquoted name
p <- xyplot(formula, data, # draws the data but not in groups
# Try these options:
# p <- xyplot(formula, data, groups, # can't find 'cat2'
# p <- xyplot(formula, data, groups = data[,grn], # can't fine grn
# p <- xyplot(formula, data, groups = grv, # can't find grv
panel = function(x, y) {
panel.stripplot(x, y, jitter.data = TRUE, pch = 20)
}
)
p
}
どちらで実行できますか:
tf(formula = mpg~vs, groups = am, data = mtcars)
groups
引数をに渡す際に私が間違っているのは何xyplot
ですか?なぜそれが見つからないのですか?どうやってgroup
情報が欲しいのかわからない。ありがとう。
アップデート:
@agstudyの回答は非常に役立ちますが、元の例のようにパネル関数を追加しても、グループはまだ認識されません(グループ化は行われませんが、エラーも発生しません)。
tf <- function(formula = NULL, data = NULL, groups = NULL) {
ll <- as.list(match.call(expand.dots = FALSE)[-1])
p <- xyplot(as.formula(ll$formula),
data = eval(ll$data),
groups = eval(ll$groups),
panel = function(x, y) {
panel.stripplot(x, y, jitter.data = TRUE, pch = 20)
}
)
p
}
まだ何かが足りない...ありがとう。