简体   繁体   中英

how to replace all special characters with DOT (.) R

Hi i Have data frame need to replace all special characters with "."

df
variabe
name:A-B c
name/A-B-c
name-A/B:c

i have tried 
df$variable =  gsub("-", ".", df$variable)
df$variable =  gsub(":", ".", df$variable)

.. Is there any function / modification to do in a single step

o/p
variabe
name.A.B.c
name.A.B.c
name.A.B.c

Thanks

我们可以使用[[:punct:]]来匹配任何标点字符并替换为.

gsub("[[:punct:]]+", ".", df$variabe)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM