| filter_x | R Documentation |
Filter a matrix or data.frame based on the sum of values, sum
of zeros, or sum of NAs in each row. Optionally filter based on only
certain columns. Also optionally perform multiple filtering steps on
different sets of columns, wherein the function is vectorised over op,
and value, and pattern (see examples).
filter_x(
data,
x = c("na", "zero", "sum"),
op = c("==", "!=", "<=", ">=", "<", ">"),
value,
pattern,
...,
setop
)
data |
|
x |
|
op |
|
value |
|
pattern |
Optional |
... |
Other arguments to be passed into |
setop |
Optional |
Returns data containing only the rows matching the
specified condition(s).
mat <- matrix(c(NA, 1:10, 0), nrow = 4, ncol = 3,
dimnames = list(NULL, c("sample1", "sample2", "sample3")))
df <- data.frame(mat)
# works with data.frame or matrix
filter_x(
data = mat,
x = "na",
op = "==",
value = 0
)
filter_x(
data = df,
x = "na",
op = "==", value = 0
)
# filter based on sum, sum of NA, or sum of zeros
filter_x(mat, "na", ">=", 1)
filter_x(mat, "sum", ">", 5)
filter_x(mat, "zero", "==", 1)
# perform multiple filtering steps at the same time
# using column name pattern matching, the results being combined with 'setop'
# ('setop' can be &, |, xor which corresponds to AND, OR, SYMMETRIC DIFFERENCE)
# (you can supply multiple 'op', 'value', and 'pattern' values in a vector)
filter_x(mat, "sum", ">", c(4, 12), c("sample[1-2]", "sample[2-3]"), setop = "&")
filter_x(mat, "sum", ">", c(4, 12), c("sample[1-2]", "sample[2-3]"), setop = "|")
filter_x(mat, "sum", ">", c(4, 12), c("sample[1-2]", "sample[2-3]"), setop = "xor")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.