I guess what you want is RLEVector of RLEVectors.jl: 
https://github.com/phaverty/RLEVectors.jl.
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
>

Reply via email to