[R] language study notes --- String Processing

String

Here Insert Picture Description

Text file reading

Use readLines()read
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
using scan()reading
wherein when a parameter sep="\n", the row read, what=specify the data type read
Here Insert Picture Description

String concatenation

Using paste()function connection string

Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description

String split

Use strsplit()function split
Here Insert Picture Description
returns a list, you can use the unlist()View
Here Insert Picture Description

String search

Using the grep()function returns the index of the default
Here Insert Picture Description
Here Insert Picture Description
use of grepl()the function, the return value is a logical value

Here Insert Picture Description
Using the regexpr()function
-1 indicates a mismatch, the match represents 1
Here Insert Picture Description
using gregexpr()the function search
returns the matching of each element in a list
Here Insert Picture Description
regexec()similar effect
Here Insert Picture Description

String replacement

sub()Character function replaces the first match, the gsub()function replaces all occurrences of characters

Here Insert Picture Description

String extraction

Use surstr()functions to extract , can be assigned directly
Here Insert Picture Description
Here Insert Picture Description

Published 125 original articles · won praise 56 · views 70000 +

Guess you like

Origin blog.csdn.net/Nicht_sehen/article/details/103263695