Replace dots using `gsub`

前端 未结 1 651
野趣味
野趣味 2021-01-22 05:46

I am trying to replace all the \".\" in a specific column of my data frame with \"/\". There are other characters in each cell and I want to make sure I only change the \".\"\'s

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 06:37

    My recommendation would be to escape the "." character:

            spy$Identifier <- gsub("\\.", "/", spy$Identifier)
    

    In regular expression, a period is a special character that matches any character. "Escaping" it tells the search to look for an actual period. In R's gsub this is accomplished with two backslashes (i.e.: "\\"). In other languages, it's often just one backslash.

    0 讨论(0)
提交回复
热议问题