
i
i
“K23166” — 2015/1/28 — 9:35 — page 16 — #42
i
i
i
i
i
i
16 CHAPTER 2. DATA MANAGEMENT
2.2.11 Set operations
newengland = c("MA", "CT", "RI", "VT", "ME", "NH")
"NY" %in% newengland
"MA" %in% newengland
Note: The first statement would return FALSE, while the second one would return TRUE.
The %in% operator also works with numeric vectors (see help("%in%")). Vector functions
for set-like operations include union(), setdiff(), setequal(), intersect(), unique(),
duplicated(), and match().
2.2.12 Find strings within string variables
Example: 7.10.9
matches = grep("pat", stringx)
positions = regexpr("pat", stringx)
> x = c("abc", "def", "abcdef", "defabc")
> grep("abc", ...