Skip to content

Pattern match in R

1 message · Richard Cotton

#
to do.
form
This is straightforward to test.
filenames <- paste("Coverage", 0:99, sep="_")
grep("Coverage_[1-9][0-9]$", filenames, value=TRUE)

This returns:
[1] "Coverage_10" "Coverage_11" "Coverage_12" "Coverage_13"
 [5] "Coverage_14" "Coverage_15" "Coverage_16" "Coverage_17"
...
[89] "Coverage_98" "Coverage_99"

If you want all the files (Coverage_0 through to coverage_99), try this 
instead:
grep("Coverage_[0-9]{1,2}$", filenames, value=TRUE)

You may wish to take a look at the Repetition section on this page:
http://www.regular-expressions.info/quickstart.html

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}