Creating ts objects in R

I just started playing with the time series in R, so I fell on the first hurdle! I have a vector of daily temperature readings (without a date stamp), and I am having problems creating such an object.

data<-rnorm(3650, m=10, sd=2)
data_ts<-as.ts(data, frequency=365, start=c(1919, 1))
attributes(data_ts)
dcomp<-decompose(data_ts, type=c("additive"))

I think this code should instruct R to make a ts object with daily measurements (frequency = 365) starting from 1-1-1919. I do not understand the error message in the decomposition command, I feel that I did not create the ts object correctly, because data_ts $ tsp does not look right!

+3
source share
1 answer
data <- rnorm(3650, m=10, sd=2)
# change is below, use ts() to create time series
data_ts <- ts(data, frequency=365, start=c(1919, 1))
attributes(data_ts)
dcomp<-decompose(data_ts, type=c("additive"))
plot(dcomp)

It produces:

Time series decomposed

+1
source

All Articles