Hi Josha,

I am not sure if there is a function like that in the standard library. But 
you can use something like this

function rsplit!(v,r)
        a = Array(Vector{eltype(v)},0)
        while length(v) >= length(r) 
            push!(a, splice!(v,r))
        end
        !isempty(v) && push!(a, v)
    return a
end

and use it like that
julia> v = rand(10)
10-element Array{Float64,1}:
 0.471785 
 0.305048 
 0.407115 
 0.696377 
 0.157388 
 0.809052 
 0.282674 
 0.885787 
 0.0478649
 0.268095 

julia> rsplit!(v,1:3)
4-element Array{Array{Float64,1},1}:
 [0.471785,0.305048,0.407115] 
 [0.696377,0.157388,0.809052] 
 [0.282674,0.885787,0.0478649]
 [0.268095]

(If you don't want to have the last entry remove the  !isempty(v)... line 
or introduce a keyword to switch it on and off). Note that v is modified by 
rsplit!

Alternatively you can reshape your vector and extract columns:
function rsplit( v, l::Int)
    m = reshape(v,l,div(length(v),l))
    return [m[:,i] for i=1:size(m,2)]
end

(Here you have to make sure that the length of v is a multiple of l)

Hope this helps,

Alex.

On Thursday, 21 May 2015 23:54:39 UTC+2, josha W wrote:
>
> R has a nice function 'split' can do this job. See the example below as 
> reference.
>
>   train_all =as.matrix(sample (1:254, 254))
>   train_5_group<-split (train_all, rep (1:5), drop=true)
>
> Is there a similar function in julia?
>
>
>

Reply via email to