An optimised version of split for the special case of splitting row indices into groups.

split_indices(group, n = 0L)

Arguments

group

Integer indices

n

The largest integer (may not appear in index). This is hint: if the largest value of group is bigger than n, the output will silently expand.

Value

A list of vectors of indices.

References

https://github.com/hadley/plyr/blob/d57f9377eb5d56107ba3136775f2f0f005f33aa3/src/split-numeric.cpp#L20

Examples

split_indices(sample(10, 100, rep = TRUE))
#> [[1]]
#>  [1] 10 15 23 26 29 35 36 46 55 62 70 87 92
#> 
#> [[2]]
#> [1]  3 20 42 85 88 89
#> 
#> [[3]]
#>  [1]  8 12 21 31 45 52 57 67 69 82 90 96
#> 
#> [[4]]
#> [1] 13 18 59 61 63 78 80
#> 
#> [[5]]
#> [1]   5   6  28  56  68  77  79  83 100
#> 
#> [[6]]
#> [1] 17 38 43 47 73 75 81 86
#> 
#> [[7]]
#>  [1]  1  2 14 24 25 27 40 44 65 66 91
#> 
#> [[8]]
#>  [1]  4  7  9 37 39 41 76 93 94 95
#> 
#> [[9]]
#>  [1] 11 16 34 50 53 58 64 71 74 84 97 98 99
#> 
#> [[10]]
#>  [1] 19 22 30 32 33 48 49 51 54 60 72
#> 
split_indices(sample(10, 100, rep = TRUE), 10)
#> [[1]]
#>  [1]  1 13 36 42 44 53 76 78 91 99
#> 
#> [[2]]
#>  [1]  2 10 12 16 24 46 51 54 69 96 97
#> 
#> [[3]]
#> [1] 26 27 34 38 50 81 88
#> 
#> [[4]]
#>  [1]  3  8 11 30 40 62 68 73 80 93
#> 
#> [[5]]
#>  [1]  5  9 17 20 25 37 49 56 57 58 59 60 79 84 86
#> 
#> [[6]]
#> [1]  6 21 66
#> 
#> [[7]]
#>  [1]  4  7 15 22 70 82 83 85 89 98
#> 
#> [[8]]
#>  [1] 14 18 28 63 67 74 90 92 94 95
#> 
#> [[9]]
#>  [1] 19 29 31 32 35 41 47 52 55 72 75
#> 
#> [[10]]
#>  [1]  23  33  39  43  45  48  61  64  65  71  77  87 100
#>