Q:

Extract date from the name of the CSV file

How can I extract 20151001 as date (like 2015-10-01) in a new vector such that the new vector is:
  File Name Date
  Residential_20151001_0000_1.csv 2015-10-01

A:

All solutions will be around extracting the date and then convert it with as.Date(,"%Y%m%d") to tell it the format.
First option with sub to extract the date:
file_name <- "Residential_20151001_0000_1.csv"
file_date <- as.Date(sub( ".*?_(\\d{8})_.*", "\\1", file_name), "%Y%m%d" )

Second option with strsplit as your file name seems separated by underscores:
file_date <- as.Date(strsplit(file_name,"_")[[1]][2], "%Y%m%d")

Other options has been given by akrun in the other answer.

A:

We can use sub, match one or more characters that are not a _ followed by -, capture the numeric part ((\\d+)) followed by characters until the end of the string.  In the replacement, we use the backreference (\\1).  After the string got extracted, we can convert to Date class with as.Date specifying the format.
as.Date(sub('[^_]+_(\\d+).*', '\\1', df1[,1]), "%Y%m%d")
#[1] "2015-10-01"

A compact option would be using str_extract with ymd
library(stringr)
library(lubridate)
ymd(str_extract(df1[,1], '\\d+'))
#[1] "2015-10-01 UTC"

Update
If we need to extract the time,
t1 <- sub('^[^_]+_[^_]+_(\\d{2})(\\d{2})_.*', '\\1:\\2', df1[,1])
t1
#[1] "00:00"
strptime(t1, format='%H:%M')

