Alberto Vieira Ferreira Monteiro
2008-Mar-08 18:38 UTC
[R] Change the index argument of a series
This is probably very trivial - so I can't find an answer in the help files. When I have a series x (x[1], x[2], ... x[n]) and I want to construct a new series y (y[1], y[2], ... y[m]) such that y's are either interpolations of the x's (when m > n) or a weighted mean (when m < n), is there any direct function to do it? For example, passing from 3 to 4 would be the same as multiplying the series by the matrix: rbind(c(3/3, 0, 0), c(1/3, 2/3, 0), c(0, 2/3, 1/3), c(0, 0, 3/3)) In the same way, passing from 4 to 3 would be the same as multiplying the series by the matrix rbind(c(3/4, 1/4, 0, 0), c(0, 2/4, 2/4, 0), c(0, 0, 1/4, 3/4)) How can I do it in a simple way? Alberto Monteiro
See ?rollapply and ?rollmean in the zoo package and ?filter and ?embed in the core of R. On Sat, Mar 8, 2008 at 1:38 PM, Alberto Vieira Ferreira Monteiro <albmont at centroin.com.br> wrote:> This is probably very trivial - so I can't find an answer in the help files. > > When I have a series x (x[1], x[2], ... x[n]) and I want to construct a > new series y (y[1], y[2], ... y[m]) such that y's are either interpolations > of the x's (when m > n) or a weighted mean (when m < n), is there > any direct function to do it? > > For example, passing from 3 to 4 would be the same as multiplying > the series by the matrix: > > rbind(c(3/3, 0, 0), > c(1/3, 2/3, 0), > c(0, 2/3, 1/3), > c(0, 0, 3/3)) > > In the same way, passing from 4 to 3 would be the same as multiplying > the series by the matrix > > rbind(c(3/4, 1/4, 0, 0), > c(0, 2/4, 2/4, 0), > c(0, 0, 1/4, 3/4)) > > How can I do it in a simple way? > > Alberto Monteiro > > ______________________________________________ > R-help at 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. >