Extended Sorting according to two attributes (I think it is grid sorting)
<p>I have the following data:</p>

<pre><code>id       brand       quantity
1        a           2
1        b           1
2        b           5
3        c           10
2        d           11
3        a           1
4        b           2
</code></pre>

<p>The output should be</p>

<pre><code>   a  b  c  d
1  2  1  0  0
2  0  5  10 11
3  1  0  10 0
4  0  2  0  0
</code></pre>

<p>How to get this type of sort in R language where the column names are brand types and row names are customer ids and the matrix data are quantity?</p>