- sub() and gsub() perform replacement of the first and all matches respectively.
- 각 함수의 기본 형태
sub(pattern, replacement, x)
gsub(pattern, replacement, x)
pattern |
The pattern or the string which you want to be replaced. |
replacement |
A input string to replace the pattern string. |
x |
A vector or a data frame to replace the string. |
# gsub() 기본 사용
## 충정로2 -> 충정로2가
addr_trim <- gsub("충정로2", "충정로2가", addr_trim)
## 합동1 & 합동2 -> 합동
addr_trim <- gsub("합동1|합동2", "합동", addr_trim)
addr_num <- gsub("[0-9]", "", addr)
gsub('.*^', 'Mr/Mrs.', df$name)