I have a data frame in a database with a date dimension that I pulled using RPostgres/RpostgreSQL and dbplyr. Each date is in the format 'YYYY-MM-DD', and I need to add a new date (or character) dimension that reflects the original date in the year-quarter format "YYYY-Q" (with a dash, not a period).
Given that I can't use lubridate with dbplyr, how would I accomplish this?
Thanks for your help! Here's a simplified version of what I have so far so you can see what packages I'm using and how I'm connecting to the database.
# Packages
library(RPostgres)
library(RPostgreSQL)
library(dplyr)
library(dbplyr)
# Connect to db
drv <- dbDriver("Postgres")
# Setup connect to db
conn <- dbConnect(drv,
dbname = etc,)
# Define table to use in db
table <- tbl(conn, in_schema("xyz", "abc"))
#Select columns and filter
df <- table %>%
#Filter for pertinent data
filter(date > as.Date("2018-01-01") & date <= as.Date("2020-01-01"))