rollapply over an index. Modify this appropriately: > z <- zoo(101:109, 11:19) > f <- function(ix) if (ix[1] < 5) min(z[ix]) else max(z[ix]) > rollapply(zoo(seq_along(z)), 3, by = 3, f) 2 5 8 101 104 109
On Thu, Jul 31, 2008 at 3:36 PM, rcoder <[EMAIL PROTECTED]> wrote: > > Hi everyone, > > I have a rollapply statement that applies a function, in steps, over a data > matrix as follows: > > #Code start > testm<-rollapply(mat, 100, by=100, min, na.rm=F) > #Code end > > This moves down matrix 'mat' and calculates the minimum value over a 100 row > range, every 100 rows (i.e. no overlaps). NAs are not removed. > > I want to modify this statement somehow so that the rollapply() stops at a > certain row in the matrix: i.e. it applies from the top, as instructed by > the statement, but only to a certain row in the matrix. Can anyone suggest a > way to do this using the additional arguments in the parentheses? One way > would be to introduce an if statement, but is this the only way? > > Thanks, > > rcoder > -- > View this message in context: > http://www.nabble.com/rollapply%28%29-to-portions-of-a-matrix-tp18761906p18761906.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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. > ______________________________________________ R-help@r-project.org mailing list 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.