I am doing analysis on hourly precipitation on a file that is disorganized. However, I managed to clean it up and store it in a dataframe (called CA1) which takes the form a
That error is a result of the shape of your data. Try > dim(rainCA1)
; I suspect it to give something like > [1] 135264 1
.
Replace rainCA1 <- ts(dat1 ...
by rainCA1 <- ts(dat1[[1]] ...
, and it should work.
Whether it does so correctly, I wonder...
It seems to me your first order of business is to get your data of a consistent format. Make sure ts()
gets the right input. Check out the precise specification of ts.
ts()
does not interpret date-time formats. ts()
requires consecutive data points with a fixed interval. It uses a major counter and a minor counter (of which frequency
fit into one major counter). For instance, if your data is hourly and you expect seasonality on the daily level, frequency
equals 24. start
and end
, therefore, are primarily cosmetic: start
merely indicates t(0) for the major counter, whereas end
signifies t(end).
If you apply dim()
in co2 or AirPassengers it will return NULL.
Thus, I suggest you to apply
dim(rainCA1)<-NULL
It worked for me many times.
One solution I found is time_series_var <- ts(data[, c("var_of_interest")])
and then time_series_var <- ts(as.vector(time_series_var))
and then the error related to univariate disappears as the dimensions are now correct.
I tried to explain the write way with a very easy example to avoid these kind of errors in another question, linked here:
stl() decomposition won't accept univariate ts object?