Day 3, A
"'Woof', he barked""\"Woof\", he barked""\\"You know about paste and paste0. I like to use sprintf(<format>, ...)
The format contains special characters starting with “%” to determine how the character should look, and data passed to the ... gets inserted into the format:
“%s” means string, “%.2f” means a float with 2 digits after the decimal
Use “%%” to get a literal percent
See also the glue package for a different way to do this.
glueglue is a package that allows you to insert R code into strings
It is quite flexible and works well with data frames as well
“… any diagnosis of either D150, D152, or D159 before the date 1 January 2010”
Regular expressions are abstract patterns of characters that describe a text sequence
You can use them with grep and related functions in base R. Also see the stringr package.
Example “starts with”
Certain characters in regexps have special meaning
^: starts with$: ends with|: or*: 0 or more times+: 1 or more times{n}: n times(...): sub-expression[...]: character classesexamples
Regexps can be very complex, but for simple patterns they can save you time
Write and double-check your pattern:
lubridatelubridate will solve most of these problems:
We will continue using the register data example to practice merging and defining new variables based on dates and strings.