2
$\begingroup$

Let's consider the following data set

data = {{1,3},{-2,4},{5,2}};

with pairs of $(x,y)$, where the $y$ values indicate the count of the $x$ values. Now I want to create a new list containing only the $x$ values with the corresponding count. For example, in the above example, the new list should contain

data2 = {1,1,1,-2,-2,-2,-2,5,5}

that is three times 1, four times -2 and two times 5.

Any suggestions?

$\endgroup$
5
$\begingroup$
ConstantArray @@@ data // Flatten

{1, 1, 1, -2, -2, -2, -2, 5, 5}

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.