R – ‘gsub’ function

gsub() function replaces all matches of a string. gsub() can also be used for Regular Expression.

gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE)

Example: eliminate space

 x <- "R Tutorial"
gsub(" ","",x)
[1] "RTutorial"

Additional information about gsub() function: http://www.endmemo.com/program/R/gsub.php

Leave a Reply