Às 16:39 de 16/01/2023, Upananda Pani escreveu:
Dear All,
I have a time series daily data with date are stored ( %dd-%mm-%yy format )
from 22-01-20 to 03-08-21. In total I have 560 observations. I am using the
following command to declare as a time series object. Here the the data set
is 7 days a week.
oil <- read_xlsx("crudefinal.xlsx")
pricet=ts(oil$price, start = c(2020, 22), freq = 365)
roilt=ts(diff(log(oil$price))*100,start=c(2020,22), freq=365)
Shall I have to declare the dates here? I want to know also if it is a 5
day trading a week, how to declare the frequency.
Looking forward to your reply
Regards,
Upananda Pani
Looking forward to your suggestions.
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Hello,
Package zoo is the best way of having dates in a time series. The
package comes with several vignettes that can get you started quickly.
See the difference between classes ts and zoo below.
# make up some test data
oil <- data.frame(price = cumsum(rnorm(560)))
oil$date <- seq(as.Date("2020-01-22"), by = "1 day", length.out = 560)
# base R
pricet <- ts(oil$price, start = c(2020, 22), freq = 365)
time(pricet)
index(pricet)
plot(pricet)
#---
library(zoo)
library(ggplot2)
pricez <- zoo(oil$price, order.by = oil$date)
time(pricez)
index(pricez)
autoplot(pricez)
vignette(package = "zoo")
Hope this helps,
Rui Barradas
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.