unique.data.frame(x) duplicated.data.frame(x) unique(x) duplicated(x)
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.
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).
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.
duplicated.data.frame
finds 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).
# 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