Re: [R] Calculate the difference using ave

2011-10-27 Thread Patrick Hausmann
Thanks Dimitris, but I would like to bind the result on the dataframe, so the length should be equal to nrow(df1). BTW, sorry for the example, it wasn't very clear, next try: # options(stringsAsFactors = FALSE) set.seed(123

Re: [R] Calculate the difference using ave

2011-10-26 Thread Dimitris Rizopoulos
Maybe one approach could be: 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)) 100 * tail(df1$tide, -3) / head(df1$water, -3) I hope it helps. Best, Dimitris On 10/26/2011 12

[R] Calculate the difference using ave

2011-10-26 Thread Patrick Hausmann
Dear R users, It may be very simple but it is being difficult for me. I'd like to calculate the difference 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),