mercredi 20 juin 2018

Delete a text in a row of a column if it doesn't start with date in R

I have an output from R with three columns. I'm trying to identify if the content of the cell in one column (sc2) starts with date, if not I'd like to delete the string in that column.

R Output

I'm still a learner, tried using a function to find date pattern and replace it with " "

del <- function(x, del){

   for (i in 1:nrow(fstat))
{
   datepat <- "([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])"

   datedetect <-str_detect(sc3,datepat) 

  if (fstat$sc3[i]== FALSE)
 {
   fstat$sc3 <- " "
 }
 }

 }

The code I tried maynot be perfect,but as I said, I'm a new learner.

Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire