Home > Software engineering >  Filter rows with incorrect date
Filter rows with incorrect date

Time:09-27

Based on the dataset below, how can I find/filter the rows with incorrect and no (NA) date values in the Request Date column?

Basically the correct dates will be something like, for example, 1/01/2022 or 11/01/2022.

Actual data

Data:

structure(list(Year = c("2022", "2022", "2022", "2022", "2022", 
"2022", "2022", "2022", "2022", "2022"), `Reference Number` = c("14784", 
"14784", "14785", "14785", "14786", "14786", "14787", "14787", 
"14788", "14788"), `Request Date` = c("1/6/2022", "1/6/2022", 
"11/19/2022", "Happy New Year", "1899-12-31 02:40:00", "Ongoing", "1//12/05", 
"01/14/205", "1/25/20`22", NA)), row.names = c(NA, -10L
), class = c("tbl_df", "tbl", "data.frame"))

Code:

library(tidyverse)

df = df %>% filter() #.... stuck

CodePudding user response:

use anytime::anytime fucntion:

df %>% filter(is.na(anytime::anytime(`Request Date`)))

# A tibble: 5 × 3
  Year  `Reference Number` `Request Date`
  <chr> <chr>              <chr>         
1 2022  14785              Happy New Year
2 2022  14787              1//12/05      
3 2022  14787              01/14/205     
4 2022  14788              1/25/20`22    
5 2022  14788              NA            
  • Related