Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

We may use between

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading