Using ddply inside a function
I'm trying to make a function using ddply inside of it. However I can't get to work. This is a dummy example reproducing what I get. Does this have anything to do this bug ? library(ggplot2) data(diamonds) foo <- function(data, fac1, fac2, bar) { res <- ddply(data, .(fac1, fac2), mean(bar)) res } foo(diamonds, "color", "cut", "price") I don't believe this is a bug. ddply expects the name of a function, which you haven't really supplied with mean(bar) . You need to write a complete function that calculates the mean you'd like: foo <- function(data, fac1, fac2, bar) { res <- ddply(data, c(fac1,