I have 2 datasets: 1 with a list of general goods and another with a list of transactions:
| Keyword | Goods |
|---|---|
| Soap A | Soap |
| Soap B | Soap |
| Shampoo | Shampoo |
| ID | Date | Txn |
|---|---|---|
| 1 | 1/22 | Soap A 100 ml |
| 1 | 1/23 | Soap A 50 ml |
| 2 | 1/24 | Soap B 100 ml |
| 2 | 1/24 | Shampoo 50 ml |
| 3 | 1/24 | Juice 100 g |
I want to create something like below that would check if the txn column matches the keyword column and create a tagging per goods for each ID (e.g. if an ID had any txns with the keyword 'Soap A' or 'Soap B', the column Soap would be tagged as 1 and 0 if not)
| ID | Soap | Shampoo |
|---|---|---|
| 1 | 1 | 0 |
| 2 | 1 | 1 |
| 3 | 0 | 0 |
I know I can make this happen by coding manually using if then statements but I have a long list of goods so I want to see if there's a more efficient way to do this through do loops.
Here's one way to do this: