I’m attempting to create a table counting the number of people engaged with per fiscal quarter using the quarter()
function of the lubridate
package.
For troubleshooting purposes, this is the reproducible dataset (simplified): https://github.com/mrkeville/stackoverflowassist/blob/2d9fe8c77b4a4366db1226f55b04fe10c11db3dc/sampledata.xlsx
According to its documentation (https://lubridate.tidyverse.org/reference/quarter.html), the quarter()
function can “take a date-time object of class POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its, ti, jul, timeSeries, fts or anything else that can be converted with as.POSIXlt”. The date column I selected is formatted as POSIXct
, and a character check yielded the following output:
str(peopledata$`Date Record Created`)
POSIXct[1:339], format: "2021-06-24" "2021-06-24" "2021-06-25" "2021-06-29" "2021-07-09" "2021-08-03" "2021-08-06" "2021-08-18" "2021-08-25" "2021-08-25" ...
I ran this function to get to the point of grouping up the dates into their fiscal quarters:
people<-peopledata%>%
select(`ID Number`,`Date Record Created`)%>%
quarter(`Date Record Created`,with_year=TRUE)
When I run the function, I get the following error:
Error in as.POSIXlt.default(x, tz = tz(x)) :
do not know how to convert 'x' to class “POSIXlt”
I attempted to then go back to the source data and run an as.Date()
conversion on the column, and it threw a different error:
Input:
peopledata<-read_excel("../People Activity.xlsx", sheet='People', col_names = T, col_types = NULL, na="", skip = 0)%>%
filter_all(any_vars(!is.na(.)))%>%
as.Date(`Date Record Created`, format = '%Y-%m-%d')
Error:
Error in as.Date.default(., `Date Record Created`, format = "%Y-%m-%d") :
do not know how to convert '.' to class “Date”
Where am I going wrong here?