0

I want to list all files from my directory that include

 20180601    
 20180602
 20180603
 20180604
 20180605

that means, all files from these 5 Days. For every day, 24 files exist. Her one example for a file name: 01-sstessa4de_20180601-030000.tsv

For reading all files from my directory, I applied:

temp <- list.files(pattern="*\\.tsv$") 

But how can I select data for just 5 days? Is there any solution with

grep

?

flozygy
  • 83
  • 2
  • 8
  • 4
    For this specific case you can use `grepl(paste0('2018060', 1:5, collapse = "|"), temp)` or `grep(paste0('2018060', 1:5, collapse = "|"), temp, value = TRUE)` . You can also create sequence of dates and then `paste` them together. – Ronak Shah Aug 01 '18 at 09:18
  • 1
    Possible duplicate https://stackoverflow.com/questions/7597559/grep-using-a-character-vector-with-multiple-patterns – Ronak Shah Aug 01 '18 at 09:36
  • `pattern="2018060[1-5].*\\.tsv$"`. – Rui Barradas Aug 01 '18 at 09:41
  • Rui: does not work, it creates an empty character – flozygy Aug 01 '18 at 09:46
  • Ronak; Think it goes into right direction. But your solution gives my just indices. Please consider, I want to read this files with read-function later to create a dataframe – flozygy Aug 01 '18 at 09:57

0 Answers0