unique: Unique elements

Description Usage Arguments Details Value See Also Examples

Description

Get the unique rows in a dataset, or identify the duplicates.

Usage

1
2
3
4
5
6
## S3 method for class 'dataset'
anyDuplicated(x, incomparables = FALSE, ...)
## S3 method for class 'dataset'
duplicated(x, incomparables = FALSE, ...)
## S3 method for class 'dataset'
unique(x, incomparables = FALSE, ...)

Arguments

x

a dataset object.

incomparables

ignored.

...

ignored.

Details

These functions convert their argument x to a dataset and identify the unique rows. They do so by first transforming the columns of x to identity proxies via the idproxy function.

Note that idproxy is not defined for list variables, so consequently anyDuplicated, duplicated, and unique will raise an error when x contains a list column.

Value

For anyDupicated, the index of the first duplicated row, or 0 if all are unique.

For duplicated, a logical vector with length equal to the number of rows in x and entries indicating whether or not each row is a duplicate of an earlier row.

For unique, a dataset with rows giving the unique rows in x.

See Also

unique, idproxy.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# identify duplicated elements
x <- dataset(one = c(  1,   1,   2,   2,   1,   1),
             two = c("a", "b", "a", "b", "a", "b"))
anyDuplicated(x)
duplicated(x)

# extract unique rows
unique(x)

# call the method explicitly to convert the argument
is.dataset(unique.dataset(mtcars))

# base-R 'unique' fails with R version < 3.5; 'unique.dataset' succeeds
x <- data.frame(first = c(.15, .10 + .05), second = c(1, 1))
unique(x$first)
unique(x)
unique.dataset(x)

patperry/r-frame documentation built on May 6, 2019, 8:34 p.m.