Skip to contents

Partition a vector into at most two subvectors

Usage

split_two(s)

Arguments

s

Vector to be split.

Value

Given a vector with no repeats, returns a list consisting of

  • a list that contains the original vector as its only element

  • other lists where each list contains two disjoint vectors whose union covers the vector. All possible unordered pairs are included.

Examples

gs <- paste0("g", 1:3)
# 4 possibilities in total
# either all genotypes in one vector (1 possibility)
# or 2 genotypes in one vector and the last in one vector (3 possibilties)
split_two(gs)
#> [[1]]
#> [[1]][[1]]
#> [1] "g1" "g2" "g3"
#> 
#> 
#> [[2]]
#> [[2]][[1]]
#> [1] "g1"
#> 
#> [[2]][[2]]
#> [1] "g2" "g3"
#> 
#> 
#> [[3]]
#> [[3]][[1]]
#> [1] "g1" "g2"
#> 
#> [[3]][[2]]
#> [1] "g3"
#> 
#> 
#> [[4]]
#> [[4]][[1]]
#> [1] "g1" "g3"
#> 
#> [[4]][[2]]
#> [1] "g2"
#> 
#>