Splits a vector (which is casted as a factor) by its elements returning a named list with the indices for each unique element of the vector.

split0(x)

Arguments

x

A vector to split.

Value

A named list according to the unique elements of x with the integer indices of those given elements.

See also

Author

Andrew E Jaffe

Examples


split0(letters[seq_len(3)])
#> $a
#> [1] 1
#> 
#> $b
#> [1] 2
#> 
#> $c
#> [1] 3
#> 

## With some repeated info
set.seed(20161005)
abc <- sample(letters[seq_len(3)], 9, replace = TRUE)
split0(abc)
#> $a
#> [1] 1 3 8
#> 
#> $b
#> [1] 2 5 7
#> 
#> $c
#> [1] 4 6 9
#>