scope {scope} | R Documentation |
Create or refine a list of vectors of row names. Each vector corresponds to a row in a data frame, and its elements identify rows relevant to that row. Relevance is determined by the passed arguments. Refinement consists of passing the output back to the function with further criteria, effectively nesting serial restrictions (scope can shrink but not grow).
scope(x, this, FUN = "==", that = x[[this]], scope = NULL)
x |
A data frame. |
this |
A column name in x , representing the first argument to FUN . |
FUN |
A function taking two arguments, typically a comparison operator. |
that |
A column name in x , representing the second argument to FUN ;
or a vector of same length as columns in x ; or an atomic value to be recycled. |
scope |
A scope object, e.g. created by previous use of scope .
Specifically, a list (same length as columns in x ) of vectors of row
names in x . |
A data frame and one of its column names must be specified (x
, this
). Defaults
are chosen so that if nothing else is specified, per-row scope will be all
rows with the same value of this
as the row in question. FUN
will operate on
this
and that
, within scope
, which is all rows, by default. All values
of this
within scope
will be compared to each value of that
. If comparison
evaluates to TRUE
, the corresponding row name is retained in scope
.
A list of vectors, one per row in x
, of relevant row names in x
.
data(Theoph) #For each row, consider only those rows with the same Subject S <- scope(x=Theoph, this='Subject', FUN='==', that='Subject') #Same effect as... S <- scope(Theoph,'Subject') #For each row within Subject, consider only those rows having non-zero times. S2 <- scope(Theoph,'Time','>',0,scope=S)