| ifelsedata | R Documentation |
Fast data.frame comparisons at the cell level
ifelsedata(x, y, arg = NULL, matchCols = FALSE)
x |
A 'data.frame' or 'matrix' |
y |
A 'data.frame' or 'matrix' of the same dimensions as 'x' or a vector with a length matching the rows of 'x' or a length 1. If 'y' is a 'data.frame' or 'matrix' with dimensions different than 'x', the larger will be trimmed to match the dimensions of the smaller. |
arg |
(Optional) A logical test expression including 'x' and 'y'. If 'arg' is not included, it is assumed that all values of 'y' are logical. |
matchCols |
(Optional) A boolean that determines if columns will be matched based on name or position. Columns will be returned in the order they are in in 'x'. Columns not present in 'x' will not be returned. Defaults to 'FALSE'. |
Returns a data.frame of the smallest size by rows and columns. The cells returned are from 'x' if the test passes and 'NA' if it does not pass.
# create dummy data
x <- data.frame(matrix(data = sample(1:10, 100, TRUE), nrow = 10, ncol = 10))
y <- data.frame(matrix(data = sample(1:10, 100, TRUE), nrow = 10, ncol = 10))
# test for equality
ifelsedata(x, y, "x >= y | x == y - 2")
# rename x columns
colnames(x) <- paste0("X", 5:14)
# match with column names
ifelsedata(x, y, "x >= y | x == y - 2", TRUE)
# match based on booleans in y
y <- data.frame(matrix(data = sample(c(TRUE, FALSE), 100, TRUE),
nrow = 10,
ncol = 10))
# test based on TRUE/FALSE in y
ifelsedata(x, y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.