我有兴趣减少一个非常大的相关矩阵以仅保留具有负关联的单元格和行。我已经使用df%>%filter_all(any_vars(.<0))
This is an example of the subset of I get later 减少了它。如何根据单元格内容选择列,而不必按名称选择:那些具有任何负值(D 和 E)的列?如果可能的话,我偏爱一个 tidyverse 的答案,但我会尽我所能。我想到了某种across()
+ if_else()
,因为我不介意将所有非负数都变成NA
,但我想不通。
ex <- tribble(~A, ~B, ~C, ~D, ~E,
"L", 0.133, 0.446, -0.0190, NA,
"M", 0.166, 0.136, 0.0893, 0.0755,
"N", 0.110, 0.159, 0.0872, -0.186,
"O", 0.0161, NA, 0.0272, -0.0767,
"P", 0.147, 0.0864, 0.0417, -0.0629)