table
correspond to rows of
x
. Works for data frames
and lists
(each variable in a list is treated like a column in a data frame).
This allows matching on multiple variables.
match(x, table, nomatch=NA) match.data.frame(x, table, nomatch=NA)
x
will be looked for in
table
.
x
.
x
does not match any
item in table. A useful alternative to
NA
is
nomatch=0
,
which has the effect that unmatched items are ignored when the
matched indices are used in subscripts.
x
giving, for each row of
x
,
the smallest
i
such that
table[i,]
equals that row.
If no value in table is equal to
x[j,]
,
then the
j
th element of the
result is
nomatch
.
In the case of lists, variables correspond to columns in a data frame,
and the
i
th
"row" of
x
is
a list containing the
i
th element
of each variable.
The function finds unique values for all variables in
table
, matches each variable in
both
x
and
table
against the corresponding unique values
to obtain numerical indices, pastes the resulting columns of numerical
indices together, then does a final matching step.
Finding unique values and the initial matching steps make use of any
methods for
unique
and
match
that have been defined.
Matrices in data frame are not supported (unless they have only one column).
# sample 10 rows randomly (but forget which were sampled) fuel.frame2 <- fuel.frame[sample(nrow(fuel.frame),10,T),] # Now figure out which rows were sampled match(fuel.frame2, fuel.frame) # which rows were used (indices) is.element(fuel.frame, fuel.frame2) # which rows were used (logical) any(duplicated(fuel.frame)) # No duplicate rows