Replace specific characters within strings

前端 未结 6 1525
悲哀的现实
悲哀的现实 2020-11-22 08:05

I would like to remove specific characters from strings within a vector, similar to the Find and Replace feature in Excel.

Here are the data I start with:<

6条回答
  •  无人共我
    2020-11-22 08:41

    With a regular expression and the function gsub():

    group <- c("12357e", "12575e", "197e18", "e18947")
    group
    [1] "12357e" "12575e" "197e18" "e18947"
    
    gsub("e", "", group)
    [1] "12357" "12575" "19718" "18947"
    

    What gsub does here is to replace each occurrence of "e" with an empty string "".


    See ?regexp or gsub for more help.

提交回复
热议问题