【问题标题】:If a string is found in any of the columns, return true in r如果在任何列中找到字符串,则在 r 中返回 true
【发布时间】:2022-12-10 04:14:59
【问题描述】:

当字符串的一部分出现在数据框的列名列表中时,我试图返回一个 TRUE/FALSE 值。我将如何做到这一点?我将附上我尝试做的事情,但在做了一些研究后可能行不通。我的想法是“%”会像 like 运算符一样工作。

"criteria.%" %in% colnames(CriteriaList)

我实际上并不想要字符串中的“%”。

【问题讨论】:

  • 试试any(grepl("criteria.%", colnames(CriteriaList), fixed = TRUE))

标签: r function dplyr


【解决方案1】:

这个可以通过any(grepl("criteria.", colnames(CriteriaList), fixed = T)解决 您还可以使用 %like% 运算符。

【讨论】:

    猜你喜欢
    • 2012-03-05
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    • 2021-11-27
    • 2021-07-31
    • 2016-06-26
    相关资源
    最近更新 更多