[R] losing row.names in matrix operations

rcoder mpdotbook at gmail.com
Sat Aug 2 16:27:07 CEST 2008


Thanks for your reply Gabor.

As I already have a dates column in my dataframe (in column row.names), is
it possible to preserve this whilst still making a data set suitable for
rollapply()?

Thanks,

rcoder



Gabor Grothendieck wrote:
> 
> If its regular you can convert it to ts or zoo.
> If its irregular convert it to zoo.  There is no
> reason to expect rollapply to work with objects
> of other classes.  Read ?ts and ?zoo.  In
> ts note the start and frequency arguments.
> 
> 
> On Sat, Aug 2, 2008 at 7:50 AM, rcoder <mpdotbook at gmail.com> wrote:
>>
>> Hi everyone,
>>
>> I have a data frame, with the following format:
>>
>> MatDate->
>>        row.names       ID1     ID2     ID3
>> 1       date1
>> 2       date1
>> 3       date3
>>        etc
>>
>> but I cannot perform a rollapply() statement on the matrix without
>> converting the matrix into a time series.
>> i.e. MatTs<-ts(MatDate)
> 
> Use the start and frequency arguments. See ?ts
> 
>>
>> Only then will my rollapply statement work:
>> MatMin<-rollapply(MatTs, 2,by=2, min, na.rm=F)
>>
>> If I apply the rollapply() statement to the dataframe, I get the
>> following
>> error: Error: could not find function "rollapply"
>>
>> The problem is that when I convert the data.frame matrix into a time
>> series
>> matrix, I lose the dates in the row.names column. I just want to know if
>> anyone could suggest a way to get around this problem, i.e. keep the
>> row.names column in place, and use the rollapply() statement as above.
>>
>> Thanks,
>>
>> rcoder
>> --
>> View this message in context:
>> http://www.nabble.com/losing-row.names-in-matrix-operations-tp18788509p18788509.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/losing-row.names-in-matrix-operations-tp18788509p18789688.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list