簡體   English   中英

filter_all 給了我相同的 dataframe 未過濾

[英]filter_all is giving me the same dataframe unfiltered

我試圖僅查找當前診斷並過濾到任何大於 2 的值。我認為我不一定會以正確的方式進行此操作,但這是我現在擁有的代碼行。 通過我所寫的內容,我剛剛返回了一個名為 FU 的數據幀,它與 FU 完全相同。 不完全確定我的問題從哪里來。

我們需要filter_at而不是filter_all

library(dplyr)
fuKSADS_1%>% 
     select(ends_with('Current')) %>%
     filter_all(any_vars( . > 2))

或者另一個選項是c_across

fuKSADS_1 %>%
     select(ends_with('Current')) %>%
     rowwise %>% 
     filter(any(c_across(everything()) > 2)) %>%
     ungroup

base R中,我們可以使用Reduce

i1 <- endsWith(names(fuKSADS_1), 'Current')
subset(fuKSADS_1[i1], Reduce(`|`, lapply(fuKSADS_1[i1], `>`, 2)))

在基礎 R 中,您可以在以"Current"結尾的列上使用rowSums

cols <- grep('Current$', names(fukSADS_1))
result <- fukSADS_1[rowSums(fukSADS_1[cols] > 2) > 0, cols]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM