[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] vector math: calculating a rolling 12 row product?
From:       Chuck Cleland <ccleland () optonline ! net>
Date:       2006-02-28 15:41:20
Message-ID: 44046F20.70106 () optonline ! net
[Download RAW message or body]

Sorry, I don't think I gave what you asked for, but cumprod() may still 
help.

Chuck Cleland wrote:
> How about applying cumprod to the columns and then subsetting the result?
> 
> apply(mydata, 2, cumprod)[12:30,]
> 
> ?cumprod
> 
> r user wrote:
>> I have a dataframe of numeric values with 30 “rows”
>> and 7 “columns”.
>>
>> For each column, beginning at “row” 12 and down to
>> “row” 30, I wish to calculate the “rolling 12 row
>> product”.  I.e., within each column, I wish to
>> multiply all the values in row 1:12, 2:13,…19:30.
>>
>> I wish to save the results as a new dataframe, which
>> will have 19 rows and 7 columns.
>>
>> ______________________________________________
>> R-help@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
>>
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894

______________________________________________
R-help@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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic