【问题标题】:Does the dplyr package function filter() work more efficiently than this?dplyr 包函数 filter() 是否比这更有效?
【发布时间】:2022-08-23 04:34:56
【问题描述】:

作为一个新手道歉,但我想知道是否有一种更有效的方法可以使用布尔值或一列在多个条件下创建子集。
我的代码如下:
AZDataInstBorder <- filter(AZDataInstActive, County == \"Cochise\" | County == \"La Paz\" | County == \"Maricopa\" | County ==\"Pima\" | \"Santa Cruz\" | County == \"Yuma\")
谢谢

  • 使用%in% 而不是==|County %in% c(\"Cochise\", ...)

标签: r dplyr


【解决方案1】:

你可以试试

AZDataInstBorder <- filter(AZDataInstActive, County %in% 
c("Cochise", "La Paz", "Maricopa", "Pima", "Santa Cruz", "Yuma")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多