Split a Dataframe

split_by(data, col, drop = FALSE, sep = ".", lex.order = FALSE)

Arguments

data

A dataframe or tibble.

col

Target column.

drop

logical indicating if levels that do not occur should be dropped (if f is a factor or a list).

sep

character string, passed to interaction in the case where f is a list.

lex.order

logical, passed to interaction when f is a list.

See also

Examples

library(tidyverse) test_data <- tibble( Group = sample(c("Apple", "Pear"), size = 10, replace = TRUE), A = sample(c(NA_integer_, 1:3), size = 10, replace = TRUE), B = sample(c(NA_integer_, 4:6), size = 10, replace = TRUE) ) # Split split_by(test_data, col = Group)
#> $Apple #> # A tibble: 4 x 3 #> Group A B #> <chr> <int> <int> #> 1 Apple 2 5 #> 2 Apple 3 5 #> 3 Apple NA NA #> 4 Apple 1 4 #> #> $Pear #> # A tibble: 6 x 3 #> Group A B #> <chr> <int> <int> #> 1 Pear 1 NA #> 2 Pear 2 NA #> 3 Pear 3 NA #> 4 Pear 1 5 #> 5 Pear 2 5 #> 6 Pear 1 NA #>
# Split Deselect split_deselect(test_data, col = Group)
#> $Apple #> # A tibble: 4 x 2 #> A B #> <int> <int> #> 1 2 5 #> 2 3 5 #> 3 NA NA #> 4 1 4 #> #> $Pear #> # A tibble: 6 x 2 #> A B #> <int> <int> #> 1 1 NA #> 2 2 NA #> 3 3 NA #> 4 1 5 #> 5 2 5 #> 6 1 NA #>