matchesCriteria | R Documentation |
are data frame rows matching given criteria?
matchesCriteria(
Data,
criteria = NULL,
na.to.false = FALSE,
add.details = FALSE,
dbg = TRUE
)
Data |
data frame |
criteria |
vector of character containing conditions, in which the
column names of |
na.to.false |
if |
add.details |
if |
dbg |
if TRUE (default) for each criterion in |
vector of logical containing TRUE at positions representing rows in
Data
fulfilling the conditions
and FALSE elsewhere
# Define an example data frame
Data <- data.frame(A = c("x", "y", "z", NA),
B = c( NA, 2, 3, 4))
# Define one or more criteria
criteria <- c("A %in% c('y', 'z')", "B %in% 1:3")
# For which rows the criteria are met (vector of logical)?
matchesCriteria(Data, criteria, dbg = FALSE)
# You may use the function in the context of indexing:
Data[matchesCriteria(Data, criteria), ]
# Filtering for non-NA values
D1 <- Data[matchesCriteria(Data, "! is.na(A) & ! is.na(B)"), ]
# the same result is returned by:
D2 <- Data[matchesCriteria(Data, c("! is.na(A)", "! is.na(B)")), ]
identical(D1, D2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.