LoveMeow
LoveMeow

Reputation: 1181

Creating ts objects in R

I have only started playing around with time series in R so I have fallen at the first hurdle! I have a vector of daily temperature readings (with no 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 be instructing R to make a ts object with daily measurements (frequency=365) starting at 1-1-1919. I dont understand the error message in the decompose command, I have a feeling I have not created the ts object correctly because data_ts$tsp does not look correct!

Upvotes: 3

Views: 9037

Answers (1)

daedalus
daedalus

Reputation: 10923

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)

Produces:

Time series decomposed

Upvotes: 2

Related Questions