I have some data which looks as follows
"ID","PROD"
"1001658",6619
"100288",11843
"100288",20106
"1004303",921
I need to convert it into a format like
"ID","PROD_6619","PROD_11843","PROD_20106","PROD_921"
"1001658",1,0,0,0
"100288",0,1,1,0
"1004303",0,0,0,1
Basically where each value in the column PROD from the original data set is in a separate column of it's own. Note that the above dataset is only a sample and I cannot hard code to be "PROD_6619","PROD_11843","PROD_20106","PROD_921". It could be much more.
I have tried writing this iteratively using a for loop and it's very slow for my huge data set.
Can you suggest me an alternative in R