I have a data frame of a few columns, the last one is called a Filename. This is how it looks like.
    Product Company Filename
       …        …       mg-tvd_bmmh_20170930.csv
       …        …       mg-tvd_bmmh_2016_06_13.csv
       …        …       …
I am trying to write a short script in R which takes dates from a filename and transforms it into a new column which I call a Date. So a new data frame would look like this:
     Product    Company   Date          Filename
       …          …       09/30/2017    mg-tvd_bmmh_20170930.csv
       …          …       16/13/2017    mg-tvd_bmmh_2016_06_13.csv
       …          …        …                …   
This is a relevant piece of my script.
   df <- mutate(df, Date <- grep(pattern = "(\d{4})_?(\d{2})_?
   (\d{1,2})", df$Filename, value = TRUE))
   ddf$Date <- as.Date(Date,format = "%m/%d/%y")
Any advice why I can't get it working?
I am getting these errors:
Error: '\d' is an unrecognized escape in character string starting ""(\d" Error in as.Date(Date, format = "%m/%d/%y") : object 'Date' not found
 
     
     
     
    