gpt4 book ai didi

r - dplyr::过滤器 "No tidyselect variables were registered"

转载 作者:行者123 更新时间:2023-12-04 10:53:23 26 4
gpt4 key购买 nike

我正在尝试使用 dplyr::filter() 过滤我的 tibble 的特定行功能。

这是我的小贴士的一部分 head(raw.tb) :

A tibble: 738 x 4
geno ind X Y
<chr> <chr> <int> <int>
1 san1w16 A1 467 383
2 san1w16 A1 465 378
3 san1w16 A1 464 378
4 san1w16 A1 464 377
5 san1w16 A1 464 376
6 san1w16 A1 464 375
7 san1w16 A1 463 375
8 san1w16 A1 463 374
9 san1w16 A1 463 373
10 san1w16 A1 463 372
# ... with 728 more rows

当我要求时: raw.tb %>% dplyr::filter(ind == contains("A"))
我得到: Error in filter_impl(.data, quo) :
Evaluation error: No tidyselect variables were registered

在我的微博中 unique(raw.tb$ind)是:
    [1] "A1"  "A10" "A11" "A12" "A2"  "A3"  "A4"  "A5"  "A6"  "A7"  "A8"  "A9"  "B1" 
[14] "B10" "B11" "B12" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" "C1" "C10"
[27] "C11" "C12" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "D1" "D10" "D11"
[40] "D12" "D2" "D3" "D4" "D5" "D6" "D7" "D8" "D9" "E1" "E10" "E11" "E12"
[53] "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "F1" "F10" "F11" "F12" "F2"
[66] "F3" "F4" "F5" "F6" "F7" "F8" "F9" "G1" "G10" "G11" "G2" "G3" "G4"
[79] "G5" "G6" "G7" "G8" "G9" "H1" "H10" "H11"

我只想提取 raw.tb$ind 的行使用 tidyverse 语言以“A”开头。

(我知道如何在基础 R 中做到这一点,但我的目标是使用 tidyverse)。

非常感谢您的任何反馈

最佳答案

filter需要一个逻辑向量来过滤行。 select辅助 ( ?select_helpers ) 函数 contains根据某种模式选择数据集的列。为了过滤行,我们可以使用 grepl来自 base R

raw.tb %>%
dplyr::filter(grepl("A", ind))

str_detect来自 stringr ( tidyverse 中的软件包之一
raw.tb %>%
dplyr::filter(stringr::str_detect(ind, "A"))

关于r - dplyr::过滤器 "No tidyselect variables were registered",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48607924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com