Skip to contents

Get a vector with all unique values found in a given column of a data.frame. Concatenated values (A,B) in the column can be returned as single values (A and B).

Usage

list_values(.data, column, split = ",")

Arguments

.data

Data frame. Data.frame to select column from.

column

Character or integer. Quoted or unqoted column name or column position.

split

Character (vector). Character or regular expression(s) passed to strsplit() to split column values before returning unique values. Defaults to ,.

Value

A vector of the same type as the given column.

Examples

# Set default connection variable
con <- connect_to_etn()
#> Error: nanodbc/nanodbc.cpp:1135: 00000: [unixODBC][Driver Manager]Data source name not found and no default driver specified 
library(dplyr) # For %>%
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

# List unique scientific_name from a dataframe containing animal information
df <- get_animals(con, animal_project_code = "2014_demer")
#> Error in methods::is(connection, "PostgreSQL"): object 'con' not found
list_values(df, "scientific_name")
#> Error: .data is not a data frame

# Or using pipe and unquoted column name
df %>% list_values(scientific_name)
#> Error: .data is not a data frame

# Or using column position
df %>% list_values(8)
#> Error: .data is not a data frame

# tag_serial_number can contain comma-separated values
df <- get_animals(con, animal_id = 5841)
#> Error in methods::is(connection, "PostgreSQL"): object 'con' not found
df$tag_serial_number
#> Error in df$tag_serial_number: object of type 'closure' is not subsettable

# list_values() will split those and return unique values
list_values(df, tag_serial_number)
#> Error: .data is not a data frame

# Another expression can be defined to split values (here ".")
list_values(df, tag_serial_number, split = "\\.")
#> Error: .data is not a data frame