How to use the strsplit function with a period

前端 未结 3 1314
渐次进展
渐次进展 2020-11-29 12:18

I would like to split the following string by its periods. I tried strsplit() with \".\" in the split argument, but did not get the re

3条回答
  •  盖世英雄少女心
    2020-11-29 12:44

    You need to either place the dot . inside of a character class or precede it with two backslashes to escape it since the dot is a character of special meaning in regex meaning "match any single character (except newline)"

    s <- 'I.want.to.split'
    strsplit(s, '\\.')
    # [[1]]
    # [1] "I"     "want"  "to"    "split"
    

提交回复
热议问题