# Creating a new data list [duplicate]

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?

• – kglr Jun 18 '19 at 10:17

ConstantArray @@@ data // Flatten