binary_col_names: names of fields which are numeric, binary or combinations...

Description Usage Arguments Value Functions Examples

View source: R/df.r

Description

Doesn't make any allowance for factors.

Usage

1
2
3
4
5
6
7
binary_col_names(x, invert = FALSE)

two_cat_col_names(x, invert = FALSE, ignore_na = FALSE, trim = TRUE)

binary_cols(x, invert = FALSE)

two_cat_cols(x, invert = FALSE)

Arguments

x

data frame

invert

single logical, if true, will return non-binary columns

ignore_na

If TRUE, then return columns with two distinct values in addition to NA. Default is FALSE, i.e. NA is counted as a distinct item.

trim

If character column found, then trim white space before assessing

Value

vector of column names

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
dat <- data.frame(c("a", "b"), c(TRUE, FALSE), c(1, 0), c(1L, 0L),
                  c(1L, 2L), c(0.1, 0.2), c("9", "8"))
names(dat) <- c("char", "bin", "binfloat", "binint",
                "int", "float", "charint")
binary_cols(dat)
binary_col_names(dat)
binary_col_names(dat, invert = TRUE)
df <- data.frame(x = c("A", "B", "A", "B"),
                 y = letters[1:4],
                 z = c("y", NA, "y", NA),
                 stringsAsFactors = FALSE)
two_cat_col_names(df)
df[1, 1] <- NA
df[2, 2] <- NA
df
stopifnot(two_cat_col_names(df) == "z")
stopifnot(two_cat_col_names(df, ignore_na = TRUE) == "x")

jackwasey/jwutil documentation built on Dec. 5, 2018, 5:31 a.m.