Split and deselect the column used to split by in a single function call.

split_deselect(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 1 4 #> 2 Apple NA NA #> 3 Apple NA 6 #> 4 Apple 3 NA #> #> $Pear #> # A tibble: 6 x 3 #> Group A B #> <chr> <int> <int> #> 1 Pear 1 6 #> 2 Pear NA 5 #> 3 Pear 1 6 #> 4 Pear 3 6 #> 5 Pear NA 6 #> 6 Pear 1 4 #>
# Split Deselect split_deselect(test_data, col = Group)
#> $Apple #> # A tibble: 4 x 2 #> A B #> <int> <int> #> 1 1 4 #> 2 NA NA #> 3 NA 6 #> 4 3 NA #> #> $Pear #> # A tibble: 6 x 2 #> A B #> <int> <int> #> 1 1 6 #> 2 NA 5 #> 3 1 6 #> 4 3 6 #> 5 NA 6 #> 6 1 4 #>