num_check {supportR}R Documentation

Check Columns for Non-Numbers

Description

Identifies any elements in the column(s) that would be changed to NA if as.numeric is used on the column(s). This is useful for quickly identifying only the "problem" entries of ostensibly numeric column(s) that is/are read in as a character.

Usage

num_check(data = NULL, col = NULL)

Arguments

data

(dataframe) object containing at least one column of supposed numbers

col

(character or numeric) name(s) or column number(s) of the column(s) containing putative numbers in the data object

Value

(list) malformed numbers from each supplied column in separate list elements

Examples

# Create dataframe with a numeric column where some entries would be coerced into NA
spp <- c('salmon', 'bass', 'halibut', 'eel')
ct <- c(1, '14x', '_23', 12)
ct2 <- c('a', '2', '4', '0')
ct3 <- c(NA, 'Y', 'typo', '2')
fish <- data.frame('species' = spp, 'count' = ct, 'num_col2' = ct2, 'third_count' = ct3)

# Use `num_check()` to return only the entries that would be lost
num_check(data = fish, col = c("count", "num_col2", "third_count"))

[Package supportR version 1.3.0 Index]