I have the following problem in R. I would like to create a ts () object (i.e. a regular time series) from an irregular time series (i.e. a list of dates and data values).
You can reproduce the problem with the following dataset and R script:
dd <- structure(list(NDVI = structure(c(14L, 4L, 11L, 12L, 20L, 17L,
5L, 7L, 21L, 23L, 25L, 19L, 15L, 9L, 3L, 24L, 2L, 6L, 22L, 16L,
13L, 18L, 10L, 8L, 1L), .Names = c("1", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23", "24", "25"), .Label = c("0.4186",
"0.5452", "0.5915", "0.5956", "0.6010", "0.6860", "0.6966", "0.7159",
"0.7161", "0.7264", "0.7281", "0.7523", "0.7542", "0.7701", "0.7751",
"0.7810", "0.7933", "0.8075", "0.8113", "0.8148", "0.8207", "0.8302",
"0.8305", "0.8369", "0.9877"), class = "factor"), DATUM = structure(c(11005,
11021, 11037, 11085, 11101, 11117, 11133, 11149, 11165, 11181,
11197, 11213, 11229, 11245, 11261, 11277, 11293, 11309, 11323,
11339, 11355, 11371, 11387, 11403, 11419), class = "Date")), .Names = c("NDVI",
"DATUM"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "25"), class = "data.frame")
require(zoo)
dd$DATUM <- as.Date(dd$DATUM,"A%Y%j")
z <- zoo(dd$NDVI,dd$DATUM,frequency=23)
z
ts.z <- as.ts(z,start=c(2000,1),frequency=23)
But this will not work, as I get a very long regular time series containing daily time steps. I would like to get a ts object with frequency = 23, correctly indicating the position for which data is not available as NA.
I tried everything based on the example given here for annual data
Converting Irregular Time Series to Regular Time Series
23 (.. 23 ). , , dd$DATUM as.Date(), , 23 .
?