[R] Problem with by statement for spaghetti plots

dadrivr dadrivr at gmail.com
Wed Sep 7 21:34:42 CEST 2011


Sorry, I thought the link would work for people because it is a public link
and it works for me when I run it in R.  Anyways, here is an example set of
data that I am having trouble with:

/id <-
c(230017,230017,230017,230018,230018,230018,230019,230019,230019,230020,230020,
       
230020,230021,230021,230021,230022,230022,230022,230023,230023,230023,230024,
        230024,230024,230025,230025,230025,230026,230026,230026)
age <- rep(c(30,36,42),10)
outcome <-
c(12,17,10,5,5,2,NA,NA,NA,8,6,5,11,13,10,15,11,15,13,NA,9,0,0,0,20,
             14,16,1,2,2)
mydata <- as.data.frame(cbind(id,age,outcome))

fit <- by(mydata, mydata$id, function(x) fitted.values(lm(outcome ~ age,
data=x))) 
fit1 <- unlist(fit) 
names(fit1) <- NULL 
interaction.plot(mydata$age, mydata$id, fit1,legend=F)/

Note that the following works fine:
/lm(outcome ~ age, data=mydata)/

Any help would be greatly appreciated.  Thanks!

--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-by-statement-for-spaghetti-plots-tp3788536p3797025.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list