如何在地址列的每条记录的开头使用gsub函数消除所有特殊字符? [英] How to use gsub function to get rid of all special characters at the start of each record of Address column?

查看:74
本文介绍了如何在地址列的每条记录的开头使用gsub函数消除所有特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Address <- c("#20 W Irving ST","@1 East Street",
             "%222 Rockfard Avenue","-145 W Locust","& 99 East Locus")
Number <- c("A-1","A-2","A-3","A-4","A-5")
DF <- data.frame(Address,Number)

推荐答案

只需在字符串开头后立即删除所有重复的标点符号或空格字符.在正则表达式中:

Just remove any repeated punctuation or space characters immediately following the start of the string. In regex speak:

gsub("^[[:punct:][:space:]]+","",DF$Address)
#[1] "20 W Irving ST"      "1 East Street"       "222 Rockfard Avenue" "145 W Locust"       
#[5] "99 East Locus" 

这篇关于如何在地址列的每条记录的开头使用gsub函数消除所有特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆