[R] Running something without a loop when the result from the previous iteration is require for the current iteration

Wu Gong wg2f at mtmail.mtsu.edu
Wed Aug 11 20:32:07 CEST 2010


Hi Adrienne,

I guess apply should be better than for loop. 

Code like this:

event.gen2 = function(genmat,use1,use2,num,ortho_obs_used){ 

      onerow.gen <- function(one.row, use1....){
              one.row[num] <- ifelse(...}
      genmat[,num] <- NA ##Add one row with NA values
      apply(genmat[-1,],1,onerow.gen,use1=...)}

And R looks TRUE as 1 and FALSE as 0, we may take advantage of it.

Regards,

Wu

-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/Running-something-without-a-loop-when-the-result-from-the-previous-iteration-is-require-for-the-currn-tp2321526p2321688.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list