This function generates subsets of a vector.
Usage
subsets(v, n = seq_along(v))
See also
Other vector helpers:
check_numeric_vector()
,
check_probability_vector()
,
chunk_vector()
,
insert_vector_entry()
,
map_indices()
,
match_numerics()
,
permutations()
,
split_vector_at()
,
vector_occurrence()
Examples
v <- 1:3
subsets(v)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
#>
#> [[4]]
#> [1] 1 2
#>
#> [[5]]
#> [1] 1 3
#>
#> [[6]]
#> [1] 2 3
#>
#> [[7]]
#> [1] 1 2 3
#>
subsets(v, c(1, 3)) # only subsets of length 1 or 3
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
#>
#> [[4]]
#> [1] 1 2 3
#>
subsets(integer()) # trivial case works
#> list()