Data Science Desktop Survival Guide
by Graham Williams |
|||||
Sub-Strings in Base R |
s <- "string manipulation"
substr(s, start=3, stop=6)
substr(s, 3, 6)
substr(s, 1, 12) <- "stip"
s
The base::substring() function performs similarly though uses last= rather than stop=. |
s <- "string manipulation"
substring(s, first=3, last=6)
x <- c("abcd", "aabcb", "babcc", "cabcd")
substring(x, 2, 4)
substring(x, 2, 4) <- "AB"
x
|