Learn R Programming

tsibble (version 1.2.0)

is_duplicated: Test duplicated observations determined by key and index variables

Description

[Stable]

  • is_duplicated(): a logical scalar if the data exist duplicated observations.

  • are_duplicated(): a logical vector, the same length as the row number of data.

  • duplicates(): identical key-index data entries.

Usage

is_duplicated(data, key = NULL, index)

are_duplicated(data, key = NULL, index, from_last = FALSE)

duplicates(data, key = NULL, index)

Arguments

data

A data frame for creating a tsibble.

key

<tidy-select> Variable(s) that uniquely determine time indices. NULL for an empty key, unquoted column names (e.g. x) for a single variable, and c() for multiple variables (e.g. c(x, y)). This argument also supports tidy-select expressions, e.g. dplyr::starts_with(), dplyr::all_of().

index

<tidy-select> A variable that contains time indices. This is commonly an unquoted column name (e.g. t), but it can also be a tidy-select expression.

from_last

TRUE does the duplication check from the last of identical elements.

Examples

Run this code
harvest <- tibble(
  year = c(2010, 2011, 2013, 2011, 2012, 2014, 2014),
  fruit = c(rep(c("kiwi", "cherry"), each = 3), "cherry"),
  kilo = sample(1:10, size = 7)
)
is_duplicated(harvest, key = fruit, index = year)
are_duplicated(harvest, key = fruit, index = year)
are_duplicated(harvest, key = fruit, index = year, from_last = TRUE)
duplicates(harvest, key = fruit, index = year)

Run the code above in your browser using DataLab