Unique or Duplicated Rows in a Data Frame, or unique combinations of multiple variables

DESCRIPTION:

Returns the unique rows of a data frame, or a logical vector denoting which rows duplicate previous rows. For a list containing multiple variables, treat the variables like columns in a data frame. This allows checking for duplicate combinations of multiple variables.

USAGE:

unique.data.frame(x) 
duplicated.data.frame(x) 
unique(x) 
duplicated(x) 

REQUIRED ARGUMENTS:

x
A data frame, or a list whose components (variables) all have the same length.

VALUE:

For a data frame,
unique returns a data frame containing the unique rows of x, and
duplicated returns a logical vector whose length is the same as the number of rows of x, that indicates for each row whether the row matches an earlier row.

For a list, variables in the list are treated like columns in a data frame;
duplicated returns a logical vector, and
unique returns a list whose variables are subsets of the original variables that correspond to unique "rows" (combinations of the variables).

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.
duplicated.data.framefinds unique values for all variables, matches each variable against the corresponding unique values, and pastes together the corresponding columns of numerical values, then checks for duplicates. This procedure allows any methods for unique and match that have been defined to be used. unique.data.frame returns the rows that duplicated.data.frame indicates are not duplicated.
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 
unique(fuel.frame[c(1,2,1,2),])     # returns two rows