当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


R corrr focus_if 有条件地聚焦相关 DataFrame

将谓词函数应用于每列相关性。计算结果为 TRUE 的列将包含在对 focus 的调用中。

用法

focus_if(x, .predicate, ..., mirror = FALSE)

参数

x

通过 as_cordf 强制关联数据帧或对象。

.predicate

应用于列的谓词函数。 .predicate 返回 TRUE 的列将作为变量包含在 focus 中。

...

如果不是匿名的,则传递给谓词函数的附加参数。

mirror

布尔值。是否镜像行中选定的列。

tibble,或者如果mirror = TRUE,则为相关数据帧。

例子

library(dplyr)
any_greater_than <- function(x, val) {
  mean(abs(x), na.rm = TRUE) > val
}

x <- correlate(mtcars)
#> Correlation computed with
#> • Method: 'pearson'
#> • Missing treated using: 'pairwise.complete.obs'

x %>% focus_if(any_greater_than, .6)
#> # A tibble: 6 × 6
#>   term     mpg    cyl   disp     hp     wt
#>   <chr>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
#> 1 drat   0.681 -0.700 -0.710 -0.449 -0.712
#> 2 qsec   0.419 -0.591 -0.434 -0.708 -0.175
#> 3 vs     0.664 -0.811 -0.710 -0.723 -0.555
#> 4 am     0.600 -0.523 -0.591 -0.243 -0.692
#> 5 gear   0.480 -0.493 -0.556 -0.126 -0.583
#> 6 carb  -0.551  0.527  0.395  0.750  0.428
x %>% focus_if(any_greater_than, .6, mirror = TRUE) %>% network_plot()

源代码:R/reshape.R

相关用法


注:本文由纯净天空筛选整理自Max Kuhn等大神的英文原创作品 Conditionally focus correlation data frame。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。