Reputation: 311
dlply() gives me an error: "Object '...' not found" when I try the smooth.spline() function with it. The example below creates some data and shows how "lm" will work but "smooth.spline" won't. Note that I am doing some arithmetic in the function arguments but that's not the reason for the error.
#some data:
df <- data.frame(count=rep(1:5,2),VSS=runif(10,0.45,0.55),
TSS=runif(10,0.9,1.3),sl=c(rep("a",5),rep("b",5)))
#works:
dlply(df,.(sl),lm,formula=VSS/TSS~count)
#doesn't work:
dlply(df,.(sl),smooth.spline,x=count,y=VSS/TSS,all.knots=TRUE)
#output:
Error in xy.coords(x,y) : Object 'VSS' not found
Any ideas???
Upvotes: 1
Views: 337
Reputation: 173587
Ugh, too much tangled evaluation and environments is likely the problem. I generally don't fight these things, I just work around them:
foo <- function(x,xvar,yvar,...){
smooth.spline(x = x[,xvar],y = x[,yvar],...)
}
df$rat <- with(df,VSS/TSS)
dlply(df,.(sl),foo,xvar = "count",yvar = "rat",all.knots = TRUE)
But there may be way to trick dlply
into doing this, I don't know.
Upvotes: 2