[R] understanding loops for "loop-plotting"

Paul Murrell p.murrell at auckland.ac.nz
Tue Feb 17 03:42:09 CET 2004


Hi

If you make the pdf() call BEFORE entering the loop does it do what you 
want?

Paul


Christian Schulz wrote:
> 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()
> }
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list