【问题标题】:Unable to remove these characters from the data in a string in r无法从 r 中的字符串中的数据中删除这些字符
【发布时间】:2022-01-14 05:34:26
【问题描述】:

我正在尝试借助以下代码从以下字符串中删除特殊字符,但没有得到结果:

图书馆(tm)

v <- "rt shibxwarrior hodl  trust  processsome great things    horizon folks    shib \n\nshib shiba shibainu shibar…"

 t <- "[\n~@!#$%&*…[]'=;]"

removespl_character <- function(x)gsub('t','',x)

cleanset_t <- tm_map(v,removespl_character)

请帮帮我..非常感谢

【问题讨论】:

    标签: r data-cleaning tm


    【解决方案1】:

    我已将模式更改为:

     v <- "rt ~@!#$%&*…[]'=; shibxwarrior[] hodl  trust  processsome great things    horizon folks    shib \n\nshib shiba shibainu shibar…"
    t <- "[~@\\!#\n$%&\\*…\\'=;]|\\]|\\["
    
    v
    gsub(pattern = t, replacement = "", x = v)
    

    我复制了你的输入:

    v <- "rt shibxwarrior hodl  trust  processsome great things    horizon folks    shib \n\nshib shiba shibainu shibar…"
    t <- "[~@\\!#\n$%&\\*…\\'=;]|\\]|\\["
    
    v
    gsub(pattern = t, replacement = "", x = v)
    

    【讨论】:

    • 为什么要介绍:rt ~@!#$%&*...[]'=; shibxwarrior[] 在给定的文本中,这是实际的文本,文本中的特殊字符应该被删除,它显示一些错误..请检查..感谢您的帮助
    • 我添加了特殊字符以确保它们被删除,因为您的示例中没有所有这些字符
    • 您是否尝试过删除它,因为在输出中它显示以下错误:UseMethod(“inspect”,x)中的错误:没有适用于“inspect”的方法应用于“字符”类的对象"
    猜你喜欢
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多