powered by
This function stratifies data based on a specified grouping column and assigns "Yes" or "No" labels according to a given percentage.
stratified_labels(df, group_col, yes_percentage)
A data frame with an additional column "Sampled_Yes_No" containing the stratified "Yes"/"No" labels.
A data frame to be stratified.
A character string specifying the column name to group by.
A numeric value between 0 and 100 indicating the percentage of "Yes" labels to assign within each group.
# Example with the iris dataset result <- stratified_labels(iris, group_col = "Species", yes_percentage = 50)
Run the code above in your browser using DataLab