added support for 1 or 3 arguments to group as matrix
This commit is contained in:
parent
e2795341d9
commit
0f28b59c5f
@ -516,6 +516,16 @@ splittable_kw(key, val::Tuple, lengthGroup) = all(splittable_kw.(key, val, lengt
|
|||||||
split_kw(key, val::AbstractArray, indices) = val[indices, fill(Colon(), ndims(val)-1)...]
|
split_kw(key, val::AbstractArray, indices) = val[indices, fill(Colon(), ndims(val)-1)...]
|
||||||
split_kw(key, val::Tuple, indices) = Tuple(split_kw(key, v, indices) for v in val)
|
split_kw(key, val::Tuple, indices) = Tuple(split_kw(key, v, indices) for v in val)
|
||||||
|
|
||||||
|
function build_arg_mat(x_ind, x, y, groupby)
|
||||||
|
y_mat = fill(NaN, length(keys(x_ind)), length(groupby.groupLabels))
|
||||||
|
for i in 1:length(groupby.groupLabels)
|
||||||
|
xi = x[groupby.groupIds[i]]
|
||||||
|
yi = y[groupby.groupIds[i]]
|
||||||
|
y_mat[getindex.(x_ind, xi), i] = yi
|
||||||
|
end
|
||||||
|
return y_mat
|
||||||
|
end
|
||||||
|
|
||||||
group_as_matrix(t) = false
|
group_as_matrix(t) = false
|
||||||
|
|
||||||
# split the group into 1 series per group, and set the label and idxfilter for each
|
# split the group into 1 series per group, and set the label and idxfilter for each
|
||||||
@ -536,16 +546,19 @@ group_as_matrix(t) = false
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
g = args[1]
|
g = args[1]
|
||||||
x, y = g.args
|
if length(g.args) == 1
|
||||||
x_u = unique(x)
|
x = zeros(Int64, lengthGroup)
|
||||||
y_mat = Array{eltype(y)}(length(x_u), length(groupby.groupLabels))
|
for indexes in groupby.groupIds
|
||||||
for i in 1:length(groupby.groupLabels)
|
x[indexes] = 1:length(indexes)
|
||||||
xi = x[groupby.groupIds[i]]
|
end
|
||||||
yi = y[groupby.groupIds[i]]
|
last_args = g.args
|
||||||
x2y = Dict(zip(xi,yi))
|
else
|
||||||
y_mat[:, i] = [get(x2y, s, NaN) for s in x_u]
|
x = g.args[1]
|
||||||
|
last_args = g.args[2:end]
|
||||||
end
|
end
|
||||||
|
x_u = unique(x)
|
||||||
|
x_ind = Dict(zip(x_u, 1:length(x_u)))
|
||||||
label --> reshape(groupby.groupLabels, 1, :)
|
label --> reshape(groupby.groupLabels, 1, :)
|
||||||
typeof(g)((x_u, y_mat))
|
typeof(g)((x_u, (build_arg_mat(x_ind, x, arg, groupby) for arg in last_args)...))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user