【问题标题】:R: How to select "and" and "or" at onceR:如何同时选择“and”和“or”
【发布时间】:2018-09-06 13:51:27
【问题描述】:

我尝试使用 R 选择一些列,但我不知道如何键入选择“条件 A 和条件 B”或“条件”。

EXAMPLE= read_spss("data13.sav") %>%   

select(starts_with("A"), -ends_with("z") | starts_with("PP"))

另外,如果我改变 |进入,它的工作原理。但是,我想选择仅以“PP”大写开头的列,但它也选择“pp”。

【问题讨论】:

    标签: r


    【解决方案1】:

    最好用matches

    read_spss("data13.sav") %>%   
           select(matches("^(A|PP).*[a-y]$"))
    

    【讨论】:

      【解决方案2】:

      你也可以设置 ignore.case = F

          read_spss("data13.sav") %>%   
          select(starts_with("A"), -ends_with("z"), starts_with("PP", ignore.case = F))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-04
        • 2018-12-08
        相关资源
        最近更新 更多