On Jul 11, 2011, at 09:55 , Anirban Mukherjee wrote: > But I am ideally looking for a way that allows one to use any formula > in lm, and still be able to mark the estimation sample. > Function/option I am missing? The best I could come up with: > >> lm.D9 <- lm(weight ~ group, model=TRUE) >> ind <- as.numeric(row.names(lm.D9$model)) >> esamp <- rep(0,length(group)) #substitute nrow(data.frame used in >> estimation) for length(group) >> esamp[ind] <- 1 >> esamp > [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 > > Is this "safe" (recommended?)?
Maybe, but you're crossing the creek to fetch water: > attr(lm.D9$model,"na.action") 18 18 attr(,"class") [1] "omit" So you could just do esamp <- rep(1, length(group)) esamp[attr(lm.D9$model,"na.action")] <- 0 -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.