Re: [R] function that calculates using preceding records

2015-02-10 Thread JS Huang
Hi, Here is an implementation: > data <- read.table("tree.txt",header=TRUE,sep=",",stringsAsFactors=FALSE) > data treecode yearrw d 1 TC149 2014NA8 2 TC149 2013 0.080 NA 3 TC149 2012 0.125 NA 4 TC149 2011 0.120 NA 5 TC149 2010 0.125 NA 6 T

Re: [R] function that calculates using preceding records

2015-02-10 Thread Seth Bigelow
that calculates using preceding records Hi: Here's another way. If I understand this correctly, you can get the diameters by setting the NA values in d to zero, taking the cumulative sum of d (within treecode) and then subtracting the result from diam[1]. Since I'm used to doing th

Re: [R] function that calculates using preceding records

2015-02-10 Thread Seth Bigelow
Petr, Your code works therefore I pronounce it beautiful. Many many thanks --Seth -Original Message- From: PIKAL Petr [mailto:petr.pi...@precheza.cz] Sent: Tuesday, February 10, 2015 11:23 AM To: Seth Bigelow; r-help@r-project.org Subject: RE: [R] function that calculates using

Re: [R] function that calculates using preceding records

2015-02-10 Thread PIKAL Petr
Hi I found an extremely ugly code :-) # first reverse levels of treecode to correspond with order of values in data frame temp$treecode<-factor(temp$treecode, rev(levels(temp$treecode))) # add zeroes and values to rw and d temp$rw[is.na(temp$rw)]<-0 library(zoo) temp$d<-na.locf(temp$d) # spl