i have a data frame with the following columns
| Vendor | Product | Price |
|---|---|---|
| 101 | 1001 | 1.50 |
| 101 | 1001 | 1.50 |
| 101 | 1001 | 1.80 |
| 102 | 1001 | 2.10 |
| 102 | 1001 | 2.10 |
| 101 | 1002 | 10.10 |
| 101 | 1002 | 10.10 |
| 101 | 1002 | 10.10 |
| 103 | 1002 | 10.10 |
| 104 | 1002 | 20.10 |
| 104 | 1002 | 20.10 |
| 104 | 1002 | 10.10 |
i need to count how many times each price shows up for each product by each vendor and create a new dataframe df2 like the following:
| Product | Vendor | Price | count of Price |
|---|---|---|---|
| 1001 | 101 | 1.5 | 2 |
| 1001 | 101 | 1.8 | 1 |
| 1001 | 102 | 2.1 | 2 |
| 1002 | 101 | 10.10 | 3 |
| 1002 | 103 | 10.10 | 1 |
| 1002 | 104 | 10.10 | 1 |
| 1002 | 104 | 20.10 | 2 |
i am new in R programming and everything i tried so far is not working. Any help would be greatly appreciated
Generating fake data:
Solution with dplyr :
Result :