Strings Flashcards
1
Q
toupper(vector_argument)
A
- Function that makes all the letters of the entries to upper case.
- Use with strings.
2
Q
tolower(vector_argument)
A
- Function that makes all the letters of the entries to lower case.
- Use with strings.
3
Q
gsub(“thing_to_remove”, “thing_to_replace_with”, what_I_want_to_remove_it_from)
A
- A function that performs “global” substitutions.
- Will substitute every occurrence of something.
- | (vertical bar) is “or” in a gsub().
- \s is interpreted as white space.
- \s+ means one or more occurrences of white spaces.
- \s+$ does \s+ matches to the end of the lines.
- =! means “not equal to”.
- ^\s+ does \s+ for spaces before the name.
- KNOW HOW TO REPLACE A COMA AND A DOLLAR SIGN (gsub(“\$|,”,”“,money) will strip all $ and , from money).
4
Q
Regular Expression
A
- Provides a concise + flexible way to specify or recognize strings.
- Its main purpose is to search, and maybe, replace.
5
Q
na.rm = TRUE
A
- An option when using function mean() to remove all missing values so that the resulting mean is not NA.
6
Q
grep()
A
- Function used to search strings and match patterns.
7
Q
grepl()
A
- Function used to search strings and matching patterns and will indicate whether it found the pattern in the string.
8
Q
nchar()
A
- Function that counts the number of characters in a string, which includes spaces.
9
Q
paste()
A
- Function that creates longer strings from shorter ones.
- Useful for making variable names.
- Clearest application of the recycling rule.
10
Q
strsplit()
A
- Function that splits strings according to a specific “split”.
- Outputs a list.
- Need to use unlist to convert this list to a vector.
11
Q
which(object_name, %in% “word_we_want”)
A
- Function that acts a locator for something in a vector and returns the indexes of where the occurrences happen.