Based on the data and code below, when I try to extract year
from the date
column, I get the following error:
Error in as.POSIXlt.character(x, tz = tz(x)) :
character string is not in a standard unambiguous format
Purpose: Create year and month columns from the date column
Data + code:
library(lubridate)
# Create sample dates
date = c("1/6/2022", "1/6/2022", "1/19/2022", "1/20/2022")
# Create a proper date column with the desired format
date_final = format(lubridate::mdy(date), '%m-%d-%Y')
# Create a year column from `date_final`
Year = lubridate::year(date_final)