I have a data frame like this:
Created with this:
companies = c("ABC Ltd", "ABC Ltd", "ABC Ltd", "Derwent plc", "Derwent plc")
sic = c("12345", "24155", "31231", "55346", "34234")
df = data.frame(companies, sic)
As you can see, the companies column is duplicated due to the SIC code.
I want to pivot wider so that each SIC code has its own column and that it is only 1 company per row.
Something like the following where I don't know how many columns there might be (i.e. there could be some companies with 20 sic codes).
I have tried pivoting it using pivot_wider
but I cannot get it to do what I need it to do.
Any help is much appreciated.