Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

keyCrossRef

keyCrossRef


Description

Checks a key for dangerous matches of old and new values in a key for different levels.

Usage

keyCrossRef(key, ignoreClass = NULL, verbose = FALSE,
  lowercase = FALSE)

Arguments

key

A variable key, ideally a long key. If a wide key is provided it is converted to long.

ignoreClass

Classes that should be excluded from check. Useful when many integer variables are being reverse- coded. Takes a string or vector.

verbose

Should a statement about the number of issues detected be returned? Defaults to FALSE.

lowercase

Should old and new values be passed through tolower function? Defaults to FALSE.

Details

Positions in a long key are referred to as levels. If a value is mismatched at levels 1 and 3, this means that issues are in rows 1 and 3 of the section of the given variable in a long key.

Value

Presents a warning for potentially problematic key sections. Return is dependent on verbose argument.

Author(s)

Ben Kite <bakite@ku.edu>

Examples

dat <- data.frame(x1 = sample(c("a", "b", "c", "d"), 100, replace = TRUE),
                  x2 = sample(c("Apple", "Orange"), 100, replace = TRUE),
                  x3 = ordered(sample(c("low", "medium", "high"), 100, replace = TRUE),
                  levels = c("low", "medium", "high")),
                  stringsAsFactors = FALSE)
key <- keyTemplate(dat, long = TRUE)
## No errors with a fresh key.
kutils:::keyCrossRef(key, verbose = TRUE)
key[1:2, "value_new"] <- c("b", "a")
key[5, "value_new"]
key[7:9, "value_new"] <- c("high", "medium", "low")
kutils:::keyCrossRef(key)
kutils:::keyCrossRef(key, ignoreClass = c("ordered", "character"), verbose = TRUE)

kutils

Project Management Tools

v1.70
GPL-2
Authors
Paul Johnson [aut, cre], Benjamin Kite [aut], Charles Redmon [aut], Jared Harpole [ctb], Kenna Whitley [ctb], Po-Yi Chen [ctb], Shadi Pirhosseinloo [ctb]
Initial release
2020-04-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.