After a year my R programming style is still very "C like".
I am still writing a lot of "for loops" and finding it difficult to recognize where, in place of loops, I could just do the
same with one line of code, using "sapply", "lapply", or the like.
On-line examples for such high level function do not help me.
Even if, sooner or later, I am getting my R scripts to do what I expect, I would really like to shake my C programming style off.
I am staring at my R script and thinking "how can I improve it ?"
For instance, I have a lot of loops similar to the following one and wonder whether I can replace them with a proper call to a high level R function that does the same:

    Nstart <- Nfour/(2^Lev) + 1
     Nfinish <- Nstart -1 + Nfour/(2^Lev)
     LengLev <- Nfinish - Nstart + 1
     NW <- floor(LengLev*N/Nfour)
     if(NW > 0){    
       for(j in Nstart:(Nstart + NW -1)){ 
          Dw <- abs(Y[j])
          Rnorm <- Rnorm + Dw^2
       }
     }


Thank you very much for helping me get better.
Maura





tutti i telefonini TIM!


	[[alternative HTML version deleted]]


