[R] plyr / spm issue

Chuck White chuckwhite8 at charter.net
Fri Jan 29 06:40:25 CET 2010


I am not able to get spm function in SemiPar to work with plyr. Here's an example:

========================================
library(plyr)
library(SemiPar)

data <- data.frame(id=c(rep("111",100),rep("222",200)), value=c(rnorm(100,2,1),rnorm(200,10,5)))

#this works
data111 <- data[data$id=="111",]
spm111 <- spm(data111$value ~ f(1:nrow(data111)))
data222 <- data[data$id=="222",]
spm222 <- spm(data222$value ~ f(1:nrow(data222)))

#this does not work
d_ply(data, c("id"), function(x) {
    spmx <- spm(x$value ~ f(1:nrow(x)))
})
========================================

Error in eval(expr, envir, enclos) : object 'x' not found



More information about the R-help mailing list