I am trying to extract only the records which has date in col1 and filter out other records. Problem is my variable does not have a fixed format of the data. So I am using regex on dplyr package in R with a pattern match. Able to filter the text data from the dataset. However not able to filter out the record which just have "2018". Any help would be really appreciated.
library(dplyr)
library(re)
library(stringr)
data1 <- data.frame( c( "sds_ds", "2018/01/11", "02/04/2018","2018"), c( 2018, 76, 35,45), c( 2017, 79, 38,46 ))
names(data1) <- c("col1", "col2", "col3")
data1
data1_clean = data1 %>%
filter(!str_detect(col1, pattern = "[a-z]"))
data1_clean