[R] Creating a new vector ( another problem)
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Nov 20 17:40:12 CET 2006
rollapply in zoo can do that. coredata extracts the data portion from
the returned zoo object:
y <- 1:20 # test data
library(zoo)
coredata(rollapply(zoo(y), 5, sum, by = 5, na.pad = TRUE, align = "r"))
On 11/20/06, Amir Safari <amsa36060 at yahoo.com> wrote:
>
>
>
>
>
> Dear R Users,
>
> Suppose we are interested for generating a new vector ( x ) from a current vector (y) of length 1000 so that x includes the sum of every 5 values in y respectively from the first to the end of length y. The same length of y for x is desired, so that other 4 positions (indices) in x are filled out with NA.
>
> For generating such a new vector, I have no idea. I tried in some ways but all were wrong and therefore I do not want to confuse you.
> How could such a purpose be coded?
> Please help me with any idea. Thank you so much for help.
> Amir Safari
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
More information about the R-help
mailing list