2

ここにはパターン/理論的根拠があるに違いありませんが、私にはそれがわかりません。変数を最初に正しく引用するにはどうすればよいですか?

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)

不足している順列や組み合わせを自由に追加してください。

4

1 に答える 1