Strings Flashcards
paste(…)
concatenate vectors after converting to character; sep= is the string to separate terms (a single space is the default); collapse= is an optional string to separate “collapsed” results
substr(x,start,stop)
substrings in a character vector; can also as- sign, as substr(x, start, stop) <- value
strsplit(x,split)
split x according to the substring split
grep(pattern,x)
searches for matches to pattern within x; see ?regex
gsub(pattern,replacement,x)
replacement of matches determined
by regular expression matching sub() is the same but only replaces
the first occurrence.
tolower(x)
convert to lowercase
toupper(x)
convert to uppercase
match(x,table)
a vector of the positions of first matches for the elements
of x among table
x %in% table
id. but returns a logical vector
pmatch(x,table)
partial matches for the elements of x among table
nchar(x)
number of characters