【问题标题】:Compare equality of a string against a set of strings比较一个字符串与一组字符串的相等性
【发布时间】:2012-05-21 16:52:08
【问题描述】:

我习惯在 SQL 中枚举字符串的可能性。

类似这样的:

select * from  s1b where Phases in ('Phase 2', 'Phase 3','Phase 4', 'Phase 2|Phase 3')

我不能使用 sqldf,因为我的 data.frame 有 posix 日期,这些日期会被损坏。所以我必须使用原生 R 方法。

如何在没有像这样复杂的 OR 代码的情况下将 data.frame 列与一组多个字符串进行比较

s1btest<-subset(s1b,s1b$Phases=='Phase 2'|s1b$Phases=='Phase 3'| more conditions here)

【问题讨论】:

    标签: r dataframe


    【解决方案1】:

    使用%in% 运算符。

    subset(s1b, Phases %in% c("Phase 2", "Phase 3"))
    

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 2014-11-09
      • 2012-12-16
      • 2016-08-10
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 2011-07-27
      • 1970-01-01
      相关资源
      最近更新 更多