binarizer: Binarize multiple columns at once

Description Usage Arguments Details Value Examples

View source: R/binarizer.R

Description

Binarize multiple columns of a dataframe based on a given threshold.

binarizer is designed to work with %>% pipelines.

binarizer_ is a standard evalution version.

Usage

1
2
3
binarizer(data, ..., thresh = 0)

binarizer_(data, cols = NULL, thresh = 0)

Arguments

data

Dataframe, tbl, vector

..., cols

Variables to include/exclude.

... : You can use same specifications as in dplyr's select.

cols : character vector

If missing, defaults to all non-grouping variables.

thresh

Threshold (Numeric).

Details

Binarizes each specified column and converts to tibble.

Value

Tibble where selected columns have been binarized.

Above thresh is 1; below or equal to thresh is 0.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Attach package
library(LRO.utilities)

# Create dataframe
df <- data.frame('a' = c(1,2,3,4,5,6,7),
                 'b' = c(2,3,4,5,6,7,8))

# First center both columns
centered_df <- scaler(df, scale = FALSE)

# Binarizing multiple columns
binarizer(centered_df)
binarizer(centered_df, a, b)
binarizer(centered_df, 1:2)
binarizer(centered_df, c(a,b))

# Binarize 'a'
binarizer(centered_df, a)

# Binarize all but 'a'
binarizer(centered_df, -a)

## Standard evalutation versions

binarizer_(centered_df, cols = c('b'))

LudvigOlsen/LRO.utilities documentation built on Nov. 13, 2020, 11:26 a.m.