[R] Need help on window() function of the 'zoo' package
ruipbarradas at sapo.pt
Sun Jun 9 10:59:36 CEST 2013
Actually, Dat_zoo is not a matrix, it is an object of classes "zooreg"
and "zoo", with a dim attribute:
And the output of window() is of the same classes but without a dim
wnd <- window(Dat_zoo, start = as.Date("2001-01-02"))
dim(wnd) # NULL
You can set the dim attribute manually like this:
dim(wnd) <- c(length(wnd), 1)
Hope this helps,
Em 08-06-2013 22:02, Ron Michael escreveu:
> 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:
>> Dat <- matrix(1:3, nc = 1)
> [1,] 1
> [2,] 2
> [3,] 3
>> Dat_zoo <- zooreg(Dat, start = as.Date("2001-01-01"), frequency = 1)
> 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 at r-project.org mailing list
> 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