encode_binary: Encode Binary Data Into 0 and 1

Description Usage Arguments Value Warning See Also Examples

Description

Encodes binary data into 0 and 1. Optionally records the result into a log file.

Usage

1
encode_binary(x, out.int=FALSE, full_print=TRUE, log = eval.parent(in_log_default))

Arguments

x

The data frame

out.int

Whether to convert encoded x to integers. Only set to TRUE when no NA in x because NAs in x causes error when converting to integers. By default, the encoded x is factorial.

full_print

When set to FALSE, only print minimum information. A full output includes summary of x before and after encoding.

log

Controls log files. To produce log files, assign it or the log_arg variable in the parent environment (dynamic scope) a list of arguments for sink(), such as file, append, and split.

Value

An encoded data frame.

Warning

x can only be a data frame. Don't pass a vector to it.

See Also

inspect_map, sink

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# refer to vignettes if you want to use log files
message('refer to vignettes if you want to use log files')

# building a data frame
A <- as.factor(c('x', 'y', 'x'))
B <- as.factor(c('y', 'x', 'y'))
C <- as.factor(c('i', 'j', 'i'))
df <- data.frame(A, B, C)

# encoding
df <- encode_binary(df)
print(df)

Example output

refer to vignettes if you want to use log files
 A     B     C    
 x:2   x:1   i:2  
 y:1   y:2   j:1  
coded 3 cols 
 A     B     C    
 0:2   0:1   0:2  
 1:1   1:2   1:1  
  A B C
1 0 1 0
2 1 0 1
3 0 1 0

cleandata documentation built on May 1, 2019, 10:25 p.m.