Check if a column in a dataframe has unique values

is_unique_column(column_name, data_frame)

Arguments

column_name

The name of the column to check for uniqueness.

data_frame

A dataframe containing the column to check.

Value

TRUE if the column has unique values, FALSE otherwise.

Examples

# Create a dataframe with a unique ID column
data_frame <- tibble::tibble(
  id = c(1, 2, 3, 4, 5),
  value = c("a", "b", "c", "d", "e")
)
is_unique_column("id", data_frame) # Returns TRUE
#> [1] TRUE

# Create a dataframe with duplicate values in the ID column
data_frame <- tibble::tibble(
  id = c(1, 2, 3, 4, 5, 1),
  value = c("a", "b", "c", "d", "e", "a")
)
is_unique_column("id", data_frame) # Returns FALSE
#> [1] FALSE