这里一定有一个模式/理由,但我就是看不到它。您如何第一次正确引用变量?
require(ggplot2)
require(reshape2)
require(plyr)
# reshape2
# These work.
dcast(mpg, manufacturer ~ class, mean, value.var = "cty")
dcast(mpg, "manufacturer ~ class", mean, value.var = "cty")
# These don't.
dcast(mpg, .(manufacturer ~ class), mean, value.var = "cty")
dcast(mpg, manufacturer ~ class, mean, value.var = cty)
dcast(mpg, manufacturer ~ class, mean, value.var = .(cty))
# plyr
# These work.
ddply(mpg, .(manufacturer), summarize, mean = mean(cty))
ddply(mpg, "manufacturer", summarize, mean = mean(cty))
ddply(mpg, manufacturer ~ class, summarize, mean = mean(cty))
# These don't.
ddply(mpg, manufacturer, summarize, mean = mean(cty))
ddply(mpg, .(manufacturer), summarize, mean = mean(.(cty)))
ddply(mpg, .(manufacturer), summarize, mean = mean("cty"))
ddply(mpg, .(manufacturer ~ class), summarize, mean = mean(cty))
ddply(mpg, "manufacturer ~ class", summarize, mean = mean(cty))
# ggplot
# This works
qplot(displ, hwy, data = mpg)
# These don't
qplot(.(displ), .(hwy), data = mpg)
qplot("displ", "hwy", data = mpg)
p <- qplot(displ, hwy, data = mpg)
# These work
p + facet_wrap(~ cyl)
p + facet_wrap(.(cyl))
p + facet_wrap("cyl")
# This doesn't
p + facet_wrap(cyl)
随意添加任何缺少的排列和组合。