Similar `rle` and `inverse_rle` functions exists in StatsBase.jl https://github.com/JuliaStats/StatsBase.jl/blob/master/src/misc.jl#L15 . These function may be enough for the application involved.
On Thursday, April 14, 2016 at 6:48:40 PM UTC+3, Kenta Sato wrote: > > I guess what you want is RLEVector of RLEVectors.jl: > https://github.com/phaverty/RLEVectors.jl > <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fphaverty%2FRLEVectors.jl&sa=D&sntz=1&usg=AFQjCNGKF-MhPi1y17Nio7t-veuFAKdaWA> > . > This does run-length encoding for repeated elements and hence applying a > function to all elements would be fast. > > > julia> v = RLEVector(vcat(zeros(10000), ones(10000))) > RLEVectors.RLEVector{Float64,Int64} > run values: [0.0,1.0] > run ends: [10000,20000] > > julia> map!(x -> x + 1, v) > RLEVectors.RLEVector{Float64,Int64} > run values: [1.0,2.0] > run ends: [10000,20000] > > > > On Thursday, April 14, 2016 at 11:48:48 PM UTC+9, Terry Seaward wrote: >> >> Hi, >> >> I have a large vector of repeated data (dates in my case, but I'd like to >> keep this generic). In R I can apply a function to the elements efficiently >> using something like this: >> >> myfun <- function(x, fun, ...) { >> ux <- unique(x); >> fun(ux, ...)[match(x, ux)] >> } >> >> myfun(x, as.character) >> >> So basically apply the function to the unique elements then use match to >> recreate x. >> >> What's the best way to do this in Julia? >> >> -- Terry >> >
