Converting to time series data (using daily/weekly data)
As you want daily time series, you need to specify your frequency as 365:
weekly_ts <- ts(dat,
freq=365,
start= c(2020,245))
Daily Time Series Analysis
ts
expects you to have values for each element of the time-series, i.e., it would expect you to have the seventh day values in the data.
One option is to expand the date index to include your missing observations. You could fill those missing observations with na.approx
or na
, but you can't give ts
a six day week and expect it to comprehend it as a seven day cycle.
A good way to do this is to look at zoo
, which has specific functions for dealing with these sorts of situations.
Analyzing weekly observations/data
Ok. So, I figured out the answer to my question:
I shouldn't be converting an object of class Date to TS because it isn't periodic. I should rather use zoo packages' classes to be consistent.
library("lubridate")
#take care of weeks:
testdata$Fiscal.Year <- paste("1/1/",testdata$Fiscal.Year,sep = "")
testdata$Fiscal.Date <- dmy(testdata$Fiscal.Year) + lubridate::weeks(testdata$Fiscal.Week)
#testdata$date_ts <- as.ts(testdata$Fiscal.Date)
ggplot(testdata,aes(x=year(testdata$Fiscal.Date),y=testdata$Product.Bookings.Net))+geom_bar(stat = "identity")
This works well.
The same holds good for the other two issues that were posted by me. I found this pdf extremely useful in my analysis: https://faculty.washington.edu/ezivot/econ424/Working%20with%20Time%20Series%20Data%20in%20R.pdf
This resolved my query. I am still open to any thoughts for reading "weekly" data and then efficiently converting it to of type "Date"
R : Converting Daily time series to monthly
The possible solution for OP issue can be based on:
#Code
y.mon<-aggregate(property_damages_in_dollars~format(as.Date(date_decision_made),
format="%Y/%m"),data=final_data, FUN=sum)
More variants can be explored around the format()
options.
Related Topics
Writing Robust R Code: Namespaces, Masking and Using the '::' Operator
How to Label a Barplot Bar with Positive and Negative Bars with Ggplot2
Delete a Column in a Data Frame Within a List
Is There a _Fast_ Way to Run a Rolling Regression Inside Data.Table
Split the Title Onto Multiple Lines
Combine Two Data Frames with All Posible Combinations
How to Nicely Annotate a Ggplot2 (Manual)
Test If an Argument of a Function Is Set or Not in R
Why Use As.Factor() Instead of Just Factor()
Insert a Logo in Upper Right Corner of R Markdown PDF Document
How to Install a Package from a Download Zip File
How to Make Variable Bar Widths in Ggplot2 Not Overlap or Gap
Plot a Line Chart with Conditional Colors Depending on Values