2

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?

Vaggelis_Z
  • 8,740
  • 6
  • 34
  • 79

1 Answers1

5
ConstantArray @@@ data // Flatten

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

Anjan Kumar
  • 4,979
  • 1
  • 15
  • 28