Tutorial by Examples

# example data test_sentences <- c("The quick brown fox quickly", "jumps over the lazy dog") Let's make the brown fox red: sub("brown","red", test_sentences) #[1] "The quick red fox quickly" "jumps over the lazy dog" Now, ...
# example data test_sentences <- c("The quick brown fox", "jumps over the lazy dog") Is there a match? grepl() is used to check whether a word or regular expression exists in a string or character vector. The function returns a TRUE/FALSE (or "Boolean") vecto...
When working with regular expressions one modifier for PCRE is g for global match. In R matching and replacement functions have two version: first match and global match: sub(pattern,replacement,text) will replace the first occurrence of pattern by replacement in text gsub(pattern,replace...
In case of big data sets, the call of grepl("fox", test_sentences) does not perform well. Big data sets are e.g. crawled websites or million of Tweets, etc. The first acceleration is the usage of the perl = TRUE option. Even faster is the option fixed = TRUE. A complete example would be: ...

Page 1 of 1