Greetings:
My dataframe has 4 variables: treecode, year, rw (tree ring width), and d (tree diameter). The d variable only has data for 2014. I wish to calculate earlier diameters by subtracting each year's growth (rw) from the previous year's diameter, by treecode. Can anyone help me with a function or statement that will do this? Sample dataset below: In this example, d in year 2013 for treecode TC149 would be 7.92 = 8.0 - 0.080. "treecode","year","rw","d" "1","TC149",2014,NA,8 "2","TC149",2013,0.08,NA "3","TC149",2012,0.125,NA "4","TC149",2011,0.12,NA "5","TC149",2010,0.125,NA "6","TC148",2014,NA,34 "7","TC148",2013,0.3,NA "8","TC148",2012,0.335,NA "9","TC148",2011,0.315,NA "10","TC148",2010,0.455,NA "11","TC147",2014,NA,55.5 "12","TC147",2013,1.26,NA "13","TC147",2012,1.115,NA "14","TC147",2011,1.025,NA "15","TC147",2010,1.495,NA "16","TC146",2014,NA,60 "17","TC146",2013,1.75,NA "18","TC146",2012,1.81,NA "19","TC146",2011,1.39,NA "20","TC146",2010,1.94,NA Seth W. Bigelow [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.