I have a For loop that is quite slow and am wondering if there is a faster
option:

df <- data.frame(TreeID=rep(1:500,each=20), Age=rep(seq(1,20,1),500))
df$Height <- exp(-0.1 + 0.2*df$Age)
df$HeightGrowth <- NA   #intialize with NA
for (i in 2:nrow(df))
 {if(df$TreeID[i]==df$TreeID[i-1])
  {df$HeightGrowth[i] <- df$Height[i]-df$Height[i-1]
  }
 }

Trevor Walker
Email: trevordaviswalker@gmail.com

	[[alternative HTML version deleted]]

