Remove all characters before a period in a string

前端 未结 5 1676
独厮守ぢ
独厮守ぢ 2020-12-09 18:01

This keeps everything before a period:

gsub(\"\\\\..*\",\"\", data$column )

how to keep everything after the period?

5条回答
  •  借酒劲吻你
    2020-12-09 18:16

    To remove all the characters before a period in a string(including period).

    gsub("^.*\\.","", data$column )
    

    Example:

    > data <- 'foobar.barfoo'
    > gsub("^.*\\.","", data)
    [1] "barfoo"
    

    To remove all the characters before the first period(including period).

    > data <- 'foo.bar.barfoo'
    > gsub("^.*?\\.","", data)
    [1] "bar.barfoo"
    

提交回复
热议问题