search for: tide_

Displaying 1 result from an estimated 1 matches for "tide_".

Did you mean: tide
2011 Oct 26
1
Calculate the difference using ave
...ifference in percent between to measures. My data looks like this: set.seed(123) df1 <- data.frame(measure = rep(c("A1", "A2", "A3"), each=3), water = sample(c(100:200), 9), tide = sample(c(-10:+10), 9)) df1 # What I want to calculate is: # tide_[A2] / water_[A1], # tide_[A3] / water_[A2] # This 'works' for the example, but I am # looking for a more general solution. df1$tide_diff <- ave(df1$tide, FUN=function(L) L / c(NA, NA, NA, df1$water)) * 100 df1 Thanks for any help! Patrick