String and Regular expressions Flashcards
[1] “base” “boot” “class” “cluster” “codetools”
to
chr [1:31] “base” “boot” “class” “cluster” “codetools” …
pkgs = gsub(“([^"]+)"([a-zA-Z0-9\.]+)"”, “\2 “, pkgs)
pkgs = unlist(strsplit(pkgs, “[[:space:]]+”))
OR
I
any word
.*
gsub()/sub()
gregexpr()/regexpr()
greedy/not-gready
space
[:space:]
Empty space between characters
\W
words = unlist(strsplit(gpl, “\W”))
words = words[words != “”]
把文本拆成单词
tail(sort(table(tolower(words))), 10)
统计词频 # 频数最大的10个单词
paste(1:3, “a”)
[1] “1 a” “2 a” “3 a”
paste(1:3, “a”, sep = “-“)
[1] “1-a” “2-a” “3-a”
paste(letters[1:10], collapse = “~”)
[1] “a~b~c~d~e~f~g~h~i~j”
paste(1:3, “a”, sep = “-“, collapse = “+”)
[1] “1-a+2-a+3-a”
gsub(“.”, “=”, “a.b.c”)
[1] “=====”
gsub(“\.”, “=”, “a.b.c”)
[1] “a=b=c”