Home > Enterprise >  How to flag a row in R if row is between two dates
How to flag a row in R if row is between two dates

Time:03-31

I have a df1 with a column called df1$date ( already turned into a date)

I need to create a flag called "net new" for any rows within the df1 that land between "2022-02-01" & "2022-04-30"

Thank you so much for your help!

df1 = df1 %\>% 
  mutate(Net_New = `Sales Order Line Item SO Line Create Date` %within% (
      ymd("2022-02-01"),
      ymd("2022-04-30"))
    ) == TRUE \~ TRUE
  )

Tried to create a column called Net New for a TRUE and FALSE but did not get close to it working.

CodePudding user response:

We may use between

library(dplyr)
library(lubridate)
df1 %>%
   mutate(New_new = between(date, ymd("2022-02-01"), ymd("2022-04-30")))
  • Related