Help pelasse ! loops in R

Hello everyone,
I have some trouble with my code :
If frost = 0 : growth_Rsk [i]= growth[i]
If frost = 1 : growth_Rsk [i+1]= start from the first value of growth vector and keep order

I appreciate your help
Thanks

time<-c(1:300)
growth<-c(0,0,0,20,17,21,25,33,35,31,21,12,9,7,5)
Myfunction <-runif(n=length(time), min=0,max=1)
frost = rep(0, length(time))
p=1/15
for (i in 1:length(Myfunction)){
if (Myfunction[i]<=p) {frost[i] = 1}
else{frost[i] = 0}
}
growth_Rsk<- vector("numeric",300)
index<-0
for(i in seq_along(frost)){
if( frost[i]==0 )index<-index+1
else index<-1
growth_Rsk[i]<-growth[index]
}

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.