October 2017
Beginner to intermediate
572 pages
26h 1m
English
The sub and gsub functions allow using regular expression to substitute a string. The sub and gsub functions perform the replacement of the first and all the other matches, respectively:
> sub("e", "q", names(iris))
Output:
[1] "Sqpal.Length" "Sqpal.Width" "Pqtal.Length" "Pqtal.Width" "Spqcies"
> gsub("e", "q", names(iris))
Output:
[1] "Sqpal.Lqngth" "Sqpal.Width" "Pqtal.Lqngth" "Pqtal.Width" "Spqciqs"
Read now
Unlock full access