[R] plyr package: passing further arguments fail
Auguie, Baptiste
ba208 at exeter.ac.uk
Sun Oct 5 15:02:18 CEST 2008
Dear list and Hadley,
The new plyr package seems to provide a clean and consistent way to apply a function on several arguments. However, I don't understand why the following example does not work like the standard mapply,
library(plyr)
df <- data.frame(a=1:10 , b=1:10)
foo1 <- function(a, b, cc=0, d=0){
a + b + cc + d
}
mdply(df, foo1, cc=1) # fine
mdply(df, foo1, d=1) # fails
mdply(df, foo1, cc=1, d=2) # fails
mapply(foo1, a=df$a, b=df$b, MoreArgs=list(cc=1))
mapply(foo1, a=df$a, b=df$b, MoreArgs=list(d=1))
mapply(foo1, a=df$a, b=df$b, MoreArgs=list(cc=1, d=2))
Best regards,
baptiste
More information about the R-help
mailing list