Learn R Programming

cheese (version 0.0.3)

divide: Divide a data frame into a list by any number of variables.

Description

Separates a data frame by one or more stratification variables into a list of data frames whose names are the strata. Removes stratification variables from each frame.

Usage

divide(
    data,
    by,
    sep = "|"
)

Arguments

data

Any data.frame.

by

Character vector of variable names or a tidyselect::select_helper.

sep

String to separate values of each stratification variable by. Defaults to "|".

Value

A named list of data.frame objects

Examples

Run this code
# NOT RUN {
require(tidyverse)

#1) Exact match
heart_disease %>%
    divide(
        by = "Sex"
    )

#2) Regular expression
heart_disease %>%
    divide(
        by = matches("^(S|H)")
    )

#3) Beginning character
heart_disease %>%
    divide(
        by = starts_with("S")
    )
    
# }

Run the code above in your browser using DataLab