Creating a new column based on two dates and renaming the time range

What is the format of Posting.Date?

That would explain sooooo much.

The format of the Posting.Date is a factor

$ Posting.Date : Factor w/ 64 levels "4/1/2019","4/10/2019",..: 17 19 19 19 19 20 20 20 20 20 ...

Convert to date like this

library(lubridate)

dmy(as.character(Posting.Date)) >= dmy("4/22/2019")

dmy() is a lubridate function that converts strings to dates. You might not need as.character(), but sometimes factors don't convert properly.

factors can be a bit tricky.

Oops you're American, you need mdy() instead.

1 Like

@MaiCabrera: since there are many different date formats in the raw data, I suggest two flexible options for standardizing them, which should work for most cases:

  1. readr::parse_date() (documentation)

  2. anytime::anydate() (documentation)

If you still get parsing error warning messages, look into those rows, and then manually apply the appropriate {lubridate} functions (eg, mdy(), ymd()) as per @woodward suggestions. Hopefully there aren’t many of these :slightly_smiling_face:

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.