Re: [R] Creating a Series of Maxima

2014-06-19 Thread arun
To get the maximum: lapply(split(df, df$Year), function(x) max(sapply(1:(nrow(x)-2), function(i) with(x, mean(Amount[i:(i+2)],na.rm=TRUE) #$`1985` #[1] 4.17 A.K. On , arun wrote: Hi, You may try: df <- structure(list()   lapply(split(df, df$Year), function(x) sapply(1:(nrow(x)-

Re: [R] Creating a Series of Maxima

2014-06-19 Thread arun
Hi, You may try: df <- structure(list()   lapply(split(df, df$Year), function(x) sapply(1:(nrow(x)-2), function(i) with(x, mean(Amount[i:(i+2)],na.rm=TRUE #$`1985` # [1] 4.167 3.833 0.833 0.333 0.333 0.000 0.000 # [8] 0.000 0.000 0.000 0.000 0.0

[R] Creating a Series of Maxima

2014-06-19 Thread Hafizuddin Arshad
Dear R users, I have this kind of data set: structure(list(Year = c(1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L), Day = 1:20, Month = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L