String and Regular expressions Flashcards

1
Q

[1] “base” “boot” “class” “cluster” “codetools”

to

chr [1:31] “base” “boot” “class” “cluster” “codetools” …

A

pkgs = gsub(“([^"]+)"([a-zA-Z0-9\.]+)"”, “\2 “, pkgs)

pkgs = unlist(strsplit(pkgs, “[[:space:]]+”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

OR

A

I

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

any word

A

.*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

gsub()/sub()

gregexpr()/regexpr()

A

greedy/not-gready

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

space

A

[:space:]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Empty space between characters

A

\W

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

words = unlist(strsplit(gpl, “\W”))

words = words[words != “”]

A

把文本拆成单词

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

tail(sort(table(tolower(words))), 10)

A

统计词频 # 频数最大的10个单词

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

paste(1:3, “a”)

A

[1] “1 a” “2 a” “3 a”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

paste(1:3, “a”, sep = “-“)

A

[1] “1-a” “2-a” “3-a”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

paste(letters[1:10], collapse = “~”)

A

[1] “a~b~c~d~e~f~g~h~i~j”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

paste(1:3, “a”, sep = “-“, collapse = “+”)

A

[1] “1-a+2-a+3-a”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

gsub(“.”, “=”, “a.b.c”)

A

[1] “=====”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

gsub(“\.”, “=”, “a.b.c”)

A

[1] “a=b=c”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly