Filters numeric columns by requiring a minimum amount of variance

min_var(x, min = 1)

Arguments

x

Input data, which should be either a data frame or matrix.

min

Minimum amount of variance to require per column.

Value

Returns data frame (or matrix, depending on input class) with all non-numeric columns and only those numeric columns that meet the minimum amount of variance.

Details

This function omits missing values.

Examples

## set seed (for replication purposes) set.seed(206195) ## create data set d <- data_set( w = rnorm(100, 0, 0.0), v = rnorm(100, 0, 0.5), x = rnorm(100, 0, 1.0), y = rnorm(100, 0, 2.0), z = rnorm(100, 0, 3.0) ) ## minimum var of 1.0 (default) min_var(d)
#> # A tibble: 100 x 3 #> x y z #> <dbl> <dbl> <dbl> #> 1 1.00 0.692 1.87 #> 2 -1.22 -0.693 3.10 #> 3 0.169 -0.0529 -0.767 #> 4 0.774 1.14 -1.89 #> 5 -0.889 1.55 -3.20 #> 6 -0.339 -0.0438 1.08 #> 7 2.11 -1.99 -0.886 #> 8 0.211 -2.91 0.0121 #> 9 -0.510 2.03 0.886 #> 10 -0.150 1.85 0.694 #> # … with 90 more rows
## min variance of 0.1 min_var(d, 0.1)
#> # A tibble: 100 x 4 #> v x y z #> <dbl> <dbl> <dbl> <dbl> #> 1 0.964 1.00 0.692 1.87 #> 2 0.648 -1.22 -0.693 3.10 #> 3 -0.308 0.169 -0.0529 -0.767 #> 4 0.170 0.774 1.14 -1.89 #> 5 -0.369 -0.889 1.55 -3.20 #> 6 0.141 -0.339 -0.0438 1.08 #> 7 0.00746 2.11 -1.99 -0.886 #> 8 0.413 0.211 -2.91 0.0121 #> 9 0.711 -0.510 2.03 0.886 #> 10 0.329 -0.150 1.85 0.694 #> # … with 90 more rows
## min var of 2.0 min_var(d, 2.0)
#> # A tibble: 100 x 2 #> y z #> <dbl> <dbl> #> 1 0.692 1.87 #> 2 -0.693 3.10 #> 3 -0.0529 -0.767 #> 4 1.14 -1.89 #> 5 1.55 -3.20 #> 6 -0.0438 1.08 #> 7 -1.99 -0.886 #> 8 -2.91 0.0121 #> 9 2.03 0.886 #> 10 1.85 0.694 #> # … with 90 more rows
## min var of 6.0 min_var(d, 6.0)
#> # A tibble: 100 x 0