13.6 Exercise 8: Regular expressions

Create the script “exercise8.R” and save it to the “Rcourse/Module2” directory: you will save all the commands of exercise 8 in that script.
Remember you can comment the code using #.

correction

1- Play with grep

  • Create the following data frame

Using grep: create the smaller data frame df3 that contains only the Patient’s but NOT the Doctor’s information.

correction

  • Use grep and one regular expression to retrieve from df2 patients/doctors coming from either Brasil or Spain. Brainstorm a bit!

correction

  • Use grep and one regular expression to retrieve from df2 patients/doctors coming from either Brasil or England.

correction

2- Play with gsub

Build this vector of file names:

Use gsub and an appropriate regular expression on vector1 to retrieve only “sample1”, “sample2”, “sample3” and “sample4”.

correction