Match rows of a data frame in another data frame, or match "rows" of lists

DESCRIPTION:

Returns a vector of indices, indicating which rows in 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.

USAGE:

match(x, table, nomatch=NA) 
match.data.frame(x, table, nomatch=NA) 

REQUIRED ARGUMENTS:

x
A data frame, or list whose variables (components) all have the same length. Rows of x will be looked for in table.
table
A data frame, or list whose variables all have the same length. This should have the same number and types of columns as x.

OPTIONAL ARGUMENTS:

nomatch
the value to be returned when an item in 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.

VALUE:

integer vector of length equal to the number of rows of 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 jth element of the result is nomatch.

DETAILS:

In the case of lists, variables correspond to columns in a data frame, and the ith "row" of x is a list containing the ith 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).

SEE ALSO:

, , , .

EXAMPLES:

# 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