I am currently learning to work with data.frame and quite confused on how to reorder them.
At the moment, I have a data.frame that shows :
- column 1: a shop name
- column 2: a product
- column 3: the number of purchase for this product by this shop
or visually something like this:
+---+-----------+-------+----------+--+
| | Shop.Name | Items | Product | |
+---+-----------+-------+----------+--+
| 1 | Shop1 | 2 | Product1 | |
| 2 | Shop1 | 4 | Product2 | |
| 3 | Shop2 | 3 | Product1 | |
| 4 | Shop3 | 2 | Product1 | |
| 5 | Shop3 | 1 | Product4 | |
+---+-----------+-------+----------+--+
What I would like to achieve is the following "shop-centric" structure:
- column 1: a shop name
- column 2: Items sold for product1
- column 3: Items sold for product2
- column 4: Items sold for product3 ...
When there is no line for a specific shop/product (because of no sales), I would like to create a 0.
or
+---+-------+-------+-------+-------+-------+-----+--+--+
| | Shop | Prod1 | Prod2 | Prod3 | Prod4 | ... | | |
+---+-------+-------+-------+-------+-------+-----+--+--+
| 1 | Shop1 | 2 | 4 | 0 | 0 | ... | | |
| 2 | Shop2 | 3 | 0 | 0 | 0 | ... | | |
| 3 | Shop3 | 2 | 0 | 0 | 1 | ... | | |
+---+-------+-------+-------+-------+-------+-----+--+--+