【问题标题】:Replace special character in a data frame column [duplicate]替换数据框列中的特殊字符[重复]
【发布时间】:2019-02-19 12:46:19
【问题描述】:

我有一个如下所示的数据框

Des              NewColumn
a                27.82 / 23.65 / 27.82
c                32.25 / 31 / 32.25 / 31

我需要/被>替换,下面是我需要的

Des              NewColumn
a                27.82 > 23.65 > 27.82
c                32.25 > 31 > 32.25 > 31

【问题讨论】:

    标签: r


    【解决方案1】:

    我们可以使用gsub

    gsub("[/]", ">", df1$NewColumn)
    

    或使用chartr

    chartr("/", ">", df1$NewColumn)
    

    【讨论】:

      【解决方案2】:

      我们可以使用stringr库:

       library(stringr)
       str_replace_all(df$NewColumn,"/",">")
      

      【讨论】:

        猜你喜欢
        • 2014-05-04
        • 1970-01-01
        • 1970-01-01
        • 2022-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-15
        相关资源
        最近更新 更多