probe {scope} | R Documentation |
For each row of a data frame, find the value in an arbitrary column and in the row where some other column has the scoped aggregated value.
probe(x, this, FUN = "max", that = this, scope = NULL, ...) select(x, from, among = NULL, where, is, ...)
x |
A data frame (probe) or a column name (select) |
this |
A column name in x , to which FUN is applied, within scope. |
FUN |
An aggregate function, preferably returning one of its arguments. |
that |
The column from which to select return values, possibly the same
as this . |
scope |
A scope object, identifying rows across which FUN is applied, or
the name of an element in x of class scope. |
... |
Extra arguments to FUN. |
from |
A data frame. |
among |
A scope object, or name of one in x. |
where |
A column in x. |
is |
A function. |
probe()
is a short-cut for a combination of skim()
, scope()
, and scoop()
. That
is, given a data frame and a scope object, aggregate on one column and use
each aggregate value to find the row (if any) where the column value matches;
return the value in an arbitrary column for that row. NA is returned if there
is not exactly one match for the aggregate.
select()
is a SQL-like reargumentation of probe()
. See example.
A vector of values of same length and mode as that
.
data(Theoph) #What is the time of the maximum concentration within subject (per row)? S <- scope(Theoph,'Subject') T <- probe(Theoph,'conc',that='Time',scope=S) U <- select('Time',from=Theoph,among=S,where='conc',is='max') # The T and U vectors above are not the same. You would need to switch 'conc' and 'Time' in # the select argument above to do the same thing.