I have a xts
object, S1
, with NA
values. My goal is to first convert S1
into a zoo
object then to impute the NA
values using the na.StrucTS
function from the zoo
package. However, when attempting this, I run into the following error:
> A_na = na.StructTS(A)
Error in rowSums(tsSmooth(StructTS(y))[, -2]) :
'x' must be an array of at least two dimensions
The structure of the variables I am working with are provided below. If any further information is needed please do let me know and I will provide further details. Thanks in advance for any help!
Details:
> require(xts)
> require(zoo)
> dput(S1)
structure(c(3.59, 3.36, 3.21, NA, NA, NA, NA, NA, NA, 3.2, 5.31,
6.73), class = c("xts", "zoo"), .indexCLASS = c("POSIXlt", "POSIXt"
), .indexTZ = "GMT", .CLASS = "double", tclass = c("POSIXlt",
"POSIXt"), tzone = "GMT", index = structure(c(1418698800, 1418702400,
1418706000, 1418709600, 1418713200, 1418716800, 1418720400, 1418724000,
1418727600, 1418731200, 1418734800, 1418738400), tzone = "GMT", tclass = c("POSIXlt",
"POSIXt")), .Dim = c(12L, 1L), .Dimnames = list(NULL, "dfxts"))
> A = as.zoo(S1)
> dput(A)
structure(c(3.59, 3.36, 3.21, NA, NA, NA, NA, NA, NA, 3.2, 5.31,
6.73), .Dim = c(12L, 1L), .Dimnames = list(NULL, "dfxts"), index = structure(list(
sec = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), hour = 3:14,
mday = c(16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L), mon = c(11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L), year = c(114L, 114L, 114L, 114L, 114L,
114L, 114L, 114L, 114L, 114L, 114L, 114L), wday = c(2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), yday = c(349L, 349L,
349L, 349L, 349L, 349L, 349L, 349L, 349L, 349L, 349L, 349L
), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L)), .Names = c("sec", "min", "hour", "mday", "mon", "year",
"wday", "yday", "isdst"), class = c("POSIXlt", "POSIXt"), tzone = "GMT"), class = "zoo")
> A_na = na.StructTS(S1)
Error in rowSums(tsSmooth(StructTS(y))[, -2]) :
'x' must be an array of at least two dimensions
However, if I run fitted(StructTS(A))
I achieve the following output:
> fitted(StructTS(A))
Time Series:
Start = 1418698800
End = 1418738400
Frequency = 0.000277777777777778
level slope
1418698800 3.590000 0.0000000
1418702400 3.360000 -0.1887519
1418706000 3.210000 -0.1563045
1418709600 3.053695 -0.1563045
1418713200 2.897391 -0.1563045
1418716800 2.741086 -0.1563045
1418720400 2.584782 -0.1563045
1418724000 2.428477 -0.1563045
1418727600 2.272173 -0.1563045
1418731200 3.200000 0.0543115
1418734800 5.310000 1.9354185
1418738400 6.730000 1.5025847