Learn R Programming

easybio (version 1.2.2)

available_ele: Extract Unique Elements from a Column with Optional Filtering

Description

Retrieves the unique, non-missing values from a specified column of a data frame. An optional expression can be provided to filter the rows of the data frame before extracting the values.

Usage

available_ele(data, col_name, subset)

Value

A vector containing the unique, non-NA values from the specified column after the optional filtering has been applied.

Arguments

data

A data frame from which to extract values.

col_name

A single string specifying the name of the target column.

subset

An optional logical expression used to subset the data frame. This expression is evaluated in the context of the data, so columns can be referred to by their names directly (e.g., Sepal.Length > 5).

Examples

Run this code
# Example 1: Get all unique species from the iris dataset
available_ele(iris, "Species")

# Example 2: Get unique species for flowers with Sepal.Length > 7
available_ele(iris, "Species", subset = Sepal.Length > 7)

# Example 3: Get unique carb values for cars with 6 cylinders
available_ele(mtcars, "carb", subset = cyl == 6)

Run the code above in your browser using DataLab