【问题标题】:How to REMOVE lower case tokens with R? [closed]如何用 R 删除小写标记? [关闭]
【发布时间】:2021-07-02 09:35:58
【问题描述】:

我正在使用 R/Quanteda,并且我正在尝试仅使用大写单词制作 wordcloud。 txt 来自 ABNT 格式的书目参考,这样做我只会保留作者的姓氏。 有什么提示吗?坦克!

【问题讨论】:

  • 嗨。欢迎来到 S.O!如果您还没有,请拨打tourminimal reproducible example 将极大地帮助这个问题,这通常是我们在这个网站上所期望的。详细了解如何使用 R here 制作这些。

标签: r quanteda


【解决方案1】:

基础 R

string <- "lowercase UPPERCASE more lower case UPPER  1143 + 40 = !!!"

gsub(" {2,}", " ", # replace 2 or more consecutive spaces with one space
  gsub("[^A-Z ]", "", string) # remove anything that's not a space or an uppercase letter
)
#> [1] " UPPERCASE UPPER "

reprex package (v2.0.0) 于 2021 年 7 月 2 日创建

Stringr 包

require(stringr)
#> Loading required package: stringr

string <- "lowercase UPPERCASE more lower case UPPER  1143 + 40 = !!!"

str_squish( # remove excess whitespace
  str_remove_all(string, "[^[:UPPER:] ]") #remove everything except uppecase and spaces
)
#> [1] "UPPERCASE UPPER"

reprex package (v2.0.0) 于 2021-07-02 创建

【讨论】:

    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    相关资源
    最近更新 更多