[R] understanding loops  for "loop-plotting"
    Christian Schulz 
    ozric at web.de
       
    Mon Feb 16 17:14:30 CET 2004
    
    
  
Hi,
i make some practice on "loops"  to understand this important
issue in "difference" to the wrappers like  apply  finally!
The point is that i want plot's for different different const  and wish in one 
pdf the 5 plots . So i want  plots for const=1:5 which change the undelying 
data expressed in t1 and t2.
I attempt  some trials , while, for  and now
repeat loop now , but didn't getting success . I get only the first plot  and 
the loop hang?
Many thanks for help ,Christian.
#modeldat  and YS are data.frames.
special <-  function(const,modeldat,YS) {
const=const
repeat {
t1  <-  apply(YS,1, function(x) {  ifelse(all(is.na(x)) | all(na.omit(x) < 
0 ,NA, which( x > const ))})
t1[is.na(t1)] <-  13
t2  <-  sapply(t1,function(x) { ifelse(x ==13,0,1)})
modeldat$MONTH  <- t1
modeldat$ACTIVE <- t2
modeldats <- na.omit(modeldat)
mod1 <-  coxph(Surv(MONTH,ACTIVE) ~  ALTER+RISIKO,data=modeldats)
pdf(file = "c:/Survivalx.pdf",    width = 6, height = 6, onefile = TRUE,
family = "Helvetica",title = "R Graphics Output")
plot(survfit(mod1),ylim=c(.7,1),xlab='Month',ylab='Proportion not Active')
const=const+1
if(const > 5) break
}
dev.off()
}
    
    
More information about the R-help
mailing list