Learn R Programming

stratifiedyh (version 0.1.0)

stratified_labels: Stratify and Assign Labels to Data

Description

This function stratifies data based on a specified grouping column and assigns "Yes" or "No" labels according to a given percentage.

Usage

stratified_labels(df, group_col, yes_percentage)

Value

A data frame with an additional column "Sampled_Yes_No" containing the stratified "Yes"/"No" labels.

Arguments

df

A data frame to be stratified.

group_col

A character string specifying the column name to group by.

yes_percentage

A numeric value between 0 and 100 indicating the percentage of "Yes" labels to assign within each group.

Examples

Run this code
# Example with the iris dataset
result <- stratified_labels(iris, group_col = "Species", yes_percentage = 50)

Run the code above in your browser using DataLab