Hi Mohammad,
You need to download and then install the zoo package. Here is an example:

> install.packages('zoo')
> require(zoo)
> x<-1:20
> 4*rollmean(x,4)
 [1] 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74

HTH,

Jorge


On Sun, Mar 1, 2009 at 10:16 PM, Mohammad Sabr <mohammad_s...@yahoo.com>wrote:

> Thanks Jorge,
>
> I tried to use the rollapply function as follows:
>
> rollapply(data_m ,4 , sum, by =1 , by.column = TRUE)
>
> but it is giving me the following error message:
>
> Error in UseMethod("rollapply") : no applicable method for "rollapply"
>
> Is there any file that I need to install or update. I reinstalled the zoo
> package but I still getting the previous problem.
>
> Thank you for your assistance,
>
>
> --- On *Sun, 3/1/09, Jorge Ivan Velez <jorgeivanve...@gmail.com>* wrote:
>
> From: Jorge Ivan Velez <jorgeivanve...@gmail.com>
> Subject: Re: [R] Partial sum of a vector
> To: "Mohammad Sabr" <mohammad_s...@yahoo.com>
> Cc: r-help@r-project.org
> Date: Sunday, March 1, 2009, 10:49 PM
>
>
> Dear Mohammad,
> Take a look at the rollmean function in the zoo package.
>
> HTH,
>
> Jorge
>
> On Sun, Mar 1, 2009 at 9:29 PM, Mohammad Sabr <mohammad_s...@yahoo.com>wrote:
>
>> I am trying to run a loop where I can sum parts of a matrix. For example,
>> I want at each step in the loop to sum the the next 4-values of a vector. I
>> tried to do the following but the result were wrong:
>>
>> for (i in 4:T) {
>> data_q[i-3,]=sum(data_m[i-3,]:data_m[i,])
>> }
>>
>> can anyone please direct me on what should I do to run this loop properly
>>
>> Thanks in advance
>>        [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> 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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to