Learn R Programming

bsearchtools (version 0.0.59)

rowfilters.DFI: Functions for row filters creation in DFI.subset.

Description

Functions for row filters creation in DFI.subset.

For information about NAs handling see details section.

Usage

RG(col,from,to) IN(col,values) EQ(col,val) EQNA(col) NOT(filter) OR(...) AND(...) "print"(x,...) "toString"(x,...) "as.character"(x,...)

Arguments

col
column name to be used in the filter condition (must be an indexed column).
from
inclusive lower-bound of the range (RG) filter condition.
to
inclusive upper-bound of the range (RG) filter condition.
values
valid values for the filter condition (used by IN).
val
valid value for the filter condition (used by EQ).
filter
filter condition to be negated (created with RG,IN,EQ,NOT,OR,AND).
...
one or more filters conditions to be put in AND or OR (created with RG,IN,EQ,NOT,OR,AND). For print, toString and as.character functions the optional arguments are currently ignored.
x
an object of class DFI.FEXPR

Value

EQ,RG,IN,EQNA,NOT,AND,OR functions return an object inheriting from class 'DFI.FEXPR' to be used as row filter in DFI.subset function. print,toString,as.character functions return the string representation of an object of class 'DFI.FEXPR'.

Details

Any filter function applied to an indexed column will filter out the NAs present in that column by default (except for EQNA). So, for example, the following filter: EQ("A",3) is actually equal to : !is.na(A) & A == 3. The functions print(filterExpr), toString(filterExpr) and as.character(filterExpr) return the string representation of the filter that you would use in a normal data.frame subset.

RG function accepts NA in from,to arguments, and this "turns off" the part of the filter set to NA. So, for instance RG("A",NA,to) will return all values A <= to<="" code=""> (but still filtering out the NA values).

EQ function accepts NA in val argument, and this simply "turns off" the filter on the column returning all the elements in the column (but still filtering out the NA values).

IN(colName,values) function is converted to OR(EQ(colName,values[1]),EQ(colName,value[2]),...) hence, if values contains NA, the filter will return all the elements in the column (but still filtering out the NA values).

EQNA(colName) function can be used to select the NAs in the column, which are excluded by the other operators.

See Also

DFI.subset

Examples

Run this code

# create the following filter: 18 <= Age <= 55 & Married == TRUE
filter <- AND(RG('Age',18,55),EQ('Married',TRUE))

# create the following filter: Age == 25 | Married == TRUE | Name == 'John'
filter <- OR(EQ('Age',25),EQ('Married',TRUE),EQ('Name','John'))

Run the code above in your browser using DataLab