I am investigating dairy stable types which have a certain code. I want to display, per farm, which types of stables there are present. In my data, every stable has it's own row, so there are multiple rows per farm when a farm has multiple stables. But I want to transform it so that every farm has one row, and each stable has it's own column.
Farm ID | Stable type |
---|---|
1 | A10 |
1 | A20 |
1 | A30 |
2 | A10 |
2 | A20 |
3 | A10 |
Desired output =
Farm ID | Stable1 | Stable2 | Stable3 |
---|---|---|---|
1 | A10 | A20 | A30 |
2 | A10 | A20 | NA |
3 | A10 | NA | NA |