Re: [R] Need help on window() function of the 'zoo' package

2013-06-09 Thread Rui Barradas

Hello,

Actually, Dat_zoo is not a matrix, it is an object of classes "zooreg" 
and "zoo", with a dim attribute:


class(Dat_zoo)
dim(Dat_zoo)

And the output of window() is of the same classes but without a dim 
attribute:


wnd <- window(Dat_zoo, start = as.Date("2001-01-02"))
class(wnd)
dim(wnd)  # NULL


You can set the dim attribute manually like this:

dim(wnd) <- c(length(wnd), 1)


Hope this helps,

Rui Barradas

Em 08-06-2013 22:02, Ron Michael escreveu:

Hi,

I observed that if I use window() function available with the 'zoo' package to 
extract a portion of my times series and if that time series data is stored in 
some 'zoo' object with only 1 column, then the resulting zoo object is becoming 
vector.

Here is my observation:


library(zoo)
Dat <- matrix(1:3, nc = 1)
Dat

  [,1]
[1,]1
[2,]2
[3,]3

Dat_zoo <- zooreg(Dat, start = as.Date("2001-01-01"), frequency = 1)
Dat_zoo


2001-01-01 1
2001-01-02 2
2001-01-03 3

window(Dat_zoo, start = as.Date("2001-01-02"))   ### why it is becoming vector? 
I want to retain it as matrix only

2001-01-02 2001-01-03
  2  3

Here you can see that, originally my 'Dat_zoo ' object was basically a matrix. 
However once I use window() function, it became vector.

Is there any possibility to retain the shape of the original object, 
particularly if that object is matrix with 1 column?

Thank you very much for your help.
[[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.



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


[R] Need help on window() function of the 'zoo' package

2013-06-08 Thread Ron Michael
Hi,
 
I observed that if I use window() function available with the 'zoo' package to 
extract a portion of my times series and if that time series data is stored in 
some 'zoo' object with only 1 column, then the resulting zoo object is becoming 
vector.
 
Here is my observation:
 
> library(zoo)
> Dat <- matrix(1:3, nc = 1)
> Dat
 [,1]
[1,]    1
[2,]    2
[3,]    3
> Dat_zoo <- zooreg(Dat, start = as.Date("2001-01-01"), frequency = 1)
> Dat_zoo
    
2001-01-01 1
2001-01-02 2
2001-01-03 3
> window(Dat_zoo, start = as.Date("2001-01-02"))   ### why it is becoming 
> vector? I want to retain it as matrix only
2001-01-02 2001-01-03 
 2  3 
 
Here you can see that, originally my 'Dat_zoo ' object was basically a matrix. 
However once I use window() function, it became vector.
 
Is there any possibility to retain the shape of the original object, 
particularly if that object is matrix with 1 column?
 
Thank you very much for your help.
[[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.