Am 04.08.2023 um 13:40 schrieb Artur Bala:
Hi,
You can try the following script:
_ _
# mymatrix: column1 = income, column2 = frequency
matrix mymatrix = {35, 5; 120, 5; 150, 0; 320, 6; 400, 5}
matrix result = {}
loop i=1..5
loop mymatrix[i,2]
result = result | {mymatrix[i,1]}
endloop
endloop
print mymatrix result
Thanks, Artur - for larger datasets one may want to avoid the inner
explicit loop and do something like:
result |= mshape(mymatrix[i,1], mymatrix[i,2], 1)
instead. (Or using indexing: result |=
mymatrix[i,1][ones(mymatrix[i,2])] -- but untested.)
I also guess that there's a clever way to avoid even the outer loop,
maybe using the Kronecker product or so.
In any case, this presupposes an exact frequency table for each
(discrete) occurring value, while for things like income one would
probably have a kind of histogram instead with bins.
cheers
sven