Dear R-User, Appreciate any helps. It looks simple, but I don't have a clue.
Given that I have a dataframe of tree population with three variables: sp=species , d0=initial_size grow=growth increment from initial size per year How can I calculate the future growth increment of each tree for the next 3 years. The following Rscript was written, #---------- a0 <- data.frame(d0=seq(5,50,5) , sp=gl(2,5,10), grow=rep(0.5,10)) a2<- list() for( i in 1:3){ a1 <- a0$d0+a0$grow a2[[i]] <- cbind(sp=a0$sp,d0=a1+i,yr=i) } as.data.frame(do.call(cbind,a2)) > as.data.frame(do.call(cbind,a2)) sp d0 yr sp d0 yr sp d0 yr 1 1 6.5 1 1 7.5 2 1 8.5 3 2 1 11.5 1 1 12.5 2 1 13.5 3 3 1 16.5 1 1 17.5 2 1 18.5 3 4 1 21.5 1 1 22.5 2 1 23.5 3 5 1 26.5 1 1 27.5 2 1 28.5 3 6 2 31.5 1 2 32.5 2 2 33.5 3 7 2 36.5 1 2 37.5 2 2 38.5 3 8 2 41.5 1 2 42.5 2 2 43.5 3 9 2 46.5 1 2 47.5 2 2 48.5 3 10 2 51.5 1 2 52.5 2 2 53.5 3 #----- but the results did not produce the expected future d0. I think its my R script "d0=a1+i" in the " a2[[i]] <- cbind(sp=a0$sp,d0=a1+i,yr=i)". Interested to know the correct way of writing the repeated loops in R. The expected results is: sp d0 yr sp d0 yr sp d0 yr 1 1 6.5 1 1 7.0 2 1 7.5 3 2 1 11.5 1 1 12.0 2 1 12.5 3 3 1 16.5 1 1 17.0 2 1 17.5 3 4 1 21.5 1 1 22.0 2 1 22.5 3 5 1 26.5 1 1 27.0 2 1 27.5 3 6 2 31.5 1 2 32.0 2 2 32.5 3 7 2 36.5 1 2 37.0 2 2 37.5 3 8 2 41.5 1 2 42.0 2 2 42.5 3 9 2 46.5 1 2 47.0 2 2 47.5 3 10 2 51.5 1 2 52.0 2 2 52.5 3 Thanking you in advance for any helps. Abd Rahman Note: the fixed grow value of 0.5 is only an example. The real data may use growth equation to calculate the increment in a single year. ________________________________________ ________________________________ For E-Mail Disclaimer, please click here<http://www.frim.gov.my/v1/support/general/email_disclaimer.cfm> [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.