Re: [R] nested loop for

2011-07-22 Thread paloma ruiz benito
eric() for (i in 1:length(data.aux$Pma)){ result.aux[i] <-sum(data.aux$SBA2[which(data.aux$dbh2> data.aux[i , ]$dbh2)]) } data$BAL2[ index.stand]<-result.aux rm(data.aux) rm(result.aux) } data Best, Paloma > Date: Thu, 21 Jul 2011 14:18:37 -0700

Re: [R] nested loop for

2011-07-21 Thread Dennis Murphy
Hi: I *think* this is what you're after, but I get dizzy trying to read convoluted loops. Try this instead; # Function to find the total SBA2 for all dbh2 larger than the given one: foo <- function(d) { d <- d[order(d$dbh2), ] d <- transform(d, BAL2 = sum(SBA2) - cumsum(SBA2)) d }

[R] nested loop for

2011-07-21 Thread paloma ruiz benito
Hi everyone, I have been working some days in a nested loop in R but I can't find the solution. I have a data.frame with an unique ID for individuals and unique ID for different stands, for each indiviadual I have a dbh record and a SBA (stand basal area) field. Pma<-rep (1:40) P<-seq(1,4,