Skip to contents

Get all unique values from variables that are available within a data frame or a list of dataframes.

Usage

get_unique_vars(data, var)

Arguments

data

Either a list of data frames or a data frame.

var

Column names to extract the unique variables from

Value

A data frame with unique values.

Examples

 list_with_data <- list(
  data.frame(
    "Sites" = c("site_1", "site_3", "site_4"),
    "ID" = c("subj_1", "subj_5", "subj_8")
    ),
 data.frame(
    "Sites" = c("site_1", "site_3", "site_9"),
    "ID" = c("subj_7", "subj_9", NA_character_)
    )
 )

 get_unique_vars(list_with_data, c("Sites", "ID"))
#>    Sites     ID
#> 1 site_1 subj_1
#> 2 site_3 subj_5
#> 3 site_4 subj_8
#> 4 site_1 subj_7
#> 5 site_3 subj_9
#> 6 site_9   <NA>