question about for loop
Hi well, we do not know how is your data organised so it is only a guess.
On 14 Dec 2006 at 13:54, Jenny persson wrote:
Date sent: Thu, 14 Dec 2006 13:54:27 +0100 (CET) From: Jenny persson <jenny197806 at yahoo.se> To: r-help at stat.math.ethz.ch Subject: [R] question about for loop
Dear R-experts, I have a dataset of 4 patients and each patient has many records at four different time points. I have done 4 different qqnorm plots on the same graph where each plot represents the records of one patient at each time point. I would like to do the same graph for the remaining patiens, but instead of repeating the below procedure three more times I would like to have a for loop so when I run the loop I would get four graphs of the four patients at the same time, where each graph has 4 different qqnorm plots representing the data at four time points for each patient. I tried to do the loop but couldn't make it work. below is the code used to the graph for one patient. sli-4 - sli_7 contain records at four time points. dat=dataset, y=records, Slide=time point
based on assumption dat has a column pat.no (numeric)
for (i in dat$pat.no)
{
dat.p<-dat[i,]
### Patient 200004
# here change all dat to dat.p
sli_4=dat$y[dat$Slide==4 & dat$Control==0] sli_5=dat$y[dat$Slide==5 & dat$Control==0] sli_6=dat$y[dat$Slide==6 & dat$Control==0] sli_7=dat$y[dat$Slide==7 & dat$Control==0] ### qq-plot of patient 200004 q_sli4<-qqnorm(sli_4,plot.it=FALSE) q_sli5<-qqnorm(sli_5,plot.it=FALSE) q_sli6<-qqnorm(sli_6,plot.it=FALSE) q_sli7<-qqnorm(sli_7,plot.it=FALSE) plot(range(q_sli4,q_sli5,q_sli6,q_sli7),range(q_sli4,q_sli5,q_sli6,q _sli7),type="n", xlab = "Theoretical Quantiles",col.main="blue", main = "Normal Q-Q Plot of index for patient 200004",ylab = "Sample
# here you shall consult expression or bquote help page
Quantiles") points(q_sli4,col=4,pch=0,cex=1)
points(q_sli5,col=3,pch=1,cex=1) points(q_sli6,col=2,pch=2,cex=1)
points(q_sli7,col=1,pch=3,cex=1) legend("topleft",c("Day 0", "56
days","112 days", "252 days"),col=c(4,3,2,1),
text.col=c(4,3,2,1),pch=c(0,1,2,3),bg="bisque") abline(0,0)
} # here is the end of your plotting However you need either to save your plots to some files (see pdf, png) or to tell to your progrem to wait with further plotting until you look at your plot. HTH Petr
Thanks alot for your help, All the bests, Jenny --------------------------------- --------------------------------- [[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch 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.
Petr Pikal petr.pikal at precheza.cz