1) dim Assuming that you have a ts
series such as the one shown below try setting its dimensions using dim<-
:
tt <- ts(1:10, start = 2000, freq = 4)
dim(tt) <- c(length(tt), 1)
dim(tt)
## [1] 10 1
class(tt)
## [1] "ts"
1a) This can alternately be written as:
tt <- ts(1:10, start = 2000, freq = 4)
tt2 <- `dim<-`(tt, c(length(tt), 1))
dim(tt2)
## [1] 10 1
class(tt2)
## [1] "ts"
frequency(tt2)
## [1] 4
start(tt2)
## [1] 2000 1
2) cbind An alternative is to use cbind
. Note that it may not display as 10x1 but it is internally which can be checked using dim(...)
.
cbind(tt, tt)[, 1, drop = FALSE]
3) zoo Unfortunately cbind(tt)
does not give a 10x1 result as one might expect but we can convert to zoo, use cbind
and convert back. Again it does not display as 10x1 but internally it is 10x1 and can be checked using dim(...)
.
library(zoo)
as.ts(cbind(as.zoo(tt)))
Most manipulations using zoo are more straight forward than with ts
so you could alternately just use zoo objects.