Updated with reproducible example and sample data.
Hi,
In the database, I have a column of dates (posixct). I am trying to create a new column by subtracting 12 months from the column of dates. But it seems lubridate
package is not supported.
Is there a way around to achieve that result using dbplyr
or another packages?
I am connecting to the database using RPostgreSQL
package and use dbplyr
package to run queries.
Thank you
library(tidyverse)
library(dbplyr)
library(RPostgreSQL)
library(lubridate)
Sample <- tibble::tribble(
~PC_pat, ~Date, ~Minus_12_months,
1L, "29/05/2011", "29/05/2010",
2L, "14/07/2010", "14/07/2009",
3L, "24/08/2013", "24/08/2012",
4L, "13/04/2011", "13/04/2010",
5L, "18/11/2012", "18/11/2011"
) %>%
mutate(Date = dmy(Date), Minus_12_months = dmy(Minus_12_months)) %>%
select(Date)
# Connecting to PostgreSQL server
drv <- dbDriver("PostgreSQL")
username <- "username"
passwords <- "passwords"
con <- DBI::dbConnect(drv, dbname = "dbase",
host = "amazonaws.com", port = 5432,
user = username, password = passwords)
Sample <- tbl(con, "Sample")
My expected result is this but lubridate is not supported in PostgreSQL. Is there a way around to get the same result
Sample %>%
mutate(Minus_12_months = Date - months(12))