Miscellaneous Functions

Miscellaneous Functions

StatsBase.rleFunction.
rle(v) -> (vals, lens)

Return the run-length encoding of a vector as a tuple. The first element of the tuple is a vector of values of the input and the second is the number of consecutive occurrences of each element.

Examples

julia> using StatsBase

julia> rle([1,1,1,2,2,3,3,3,3,2,2,2])
([1, 2, 3, 2], [3, 2, 4, 3])
source
StatsBase.inverse_rleFunction.
inverse_rle(vals, lens)

Reconstruct a vector from its run-length encoding (see rle). vals is a vector of the values and lens is a vector of the corresponding run lengths.

source
StatsBase.levelsmapFunction.
levelsmap(a)

Construct a dictionary that maps each of the n unique values in a to a number between 1 and n.

source
StatsBase.indexmapFunction.
indexmap(a)

Construct a dictionary that maps each unique value in a to the index of its first occurrence in a.

source
indicatormat(x, k::Integer; sparse=false)

Construct a boolean matrix I of size (k, length(x)) such that I[x[i], i] = true and all other elements are set to false. If sparse is true, the output will be a sparse matrix, otherwise it will be dense (default).

Examples

julia> using StatsBase

julia> indicatormat([1 2 2], 2)
2×3 Array{Bool,2}:
  true  false  false
 false   true   true
source
indicatormat(x, c=sort(unique(x)); sparse=false)

Construct a boolean matrix I of size (length(c), length(x)). Let ci be the index of x[i] in c. Then I[ci, i] = true and all other elements are false.

source