cryo111
cryo111

Reputation: 4474

zoo time series loses colname information after reducing a multivariate to a univariate time series

Let's say we have the following multivariate time series

A=zoo(data.frame(x=100:101,y=200:201,z=300:301),1:2)

Everything is fine with colnames(A) here. The function gives

[1] "x" "y" "z"

Now select a specific date of the time series

B=A[1,]

colnames(B) gives the same result as above. So, everything is still fine.

Let's further reduce the time series by

C=B[,abs(B)>=300]

In this case, colnames(C) returns NULL. That is, the column name information z is lost.

Any pointers to how to fix this? Thank you!

Upvotes: 1

Views: 194

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176658

Set drop=FALSE:

C=B[,abs(B)>=300,drop=FALSE]

Upvotes: 3

Related Questions