| split_by | R Documentation |
Split up a data frame based on variable expressions or on conditions to receive multiple smaller data frames.
split_by_var(data_frame, variable)
split_by_condition(data_frame, ..., inverse = FALSE)
data_frame |
A data frame which should be split up into multiple data frames. |
variable |
In |
... |
In |
inverse |
In |
split_by() is based on the explicit Output from 'SAS'. With the Output function
one can - among other things - explicitly tell 'SAS' which observation to output into
which data set. Which enables the user to output one observation into one or multiple
data sets.
Instead of subsetting the same data frame multiple times manually, you can subset it multiple times at once with this function.
split_by_var(): Returns a list of data frames split by variable expressions.
The lists names are the variable expressions.
split_by_condition(): Returns a list of data frames split conditionally.
The lists names are the conditions.
# Example data frame
my_data <- dummy_data(1000)
# Split by variable expressions
split_var_df <- my_data |> split_by_var(sex)
# Split by conditions
split_cond_df <- my_data |> split_by_condition(sex == 1 & age < 18,
sex == 2 & age >= 18)
# Split by condition with inverse group
split_inv_df <- my_data |> split_by_condition(sex == 1, inverse = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.