r - Select only matching files using multiple patterns in list.files -
i have following csv files , want select ones have matching 'pop' , 'throughput' values in each string:
example_pop_high_throughput_high_strategy.csv example_pop_high_throughput_base_strategy.csv example_pop_high_throughput_low_strategy.csv example_pop_base_throughput_high_strategy.csv example_pop_base_throughput_base_strategy.csv example_pop_base_throughput_low_strategy.csv example_pop_low_throughput_high_strategy.csv example_pop_low_throughput_base_strategy.csv example_pop_low_throughput_low_strategy.csv i want these:
example_pop_high_throughput_high_strategy.csv example_pop_base_throughput_base_strategy.csv example_pop_low_throughput_low_strategy.csv i can use list.files select files with, example, 'high':
file_names <- list.files("made/up/path", pattern = c("high")) although, trying twice match 'high' , 'high', didn't work:
file_names <- list.files("made/up/path", pattern = c("high", "high")) is there way select files matching 'pop' , 'throughput' values, preferably in single expression?
the following should work:
file_names <- list.files("made/up/path", pattern = c("(low|base|high).+\\1")) wiki
Comments
Post a Comment