I have a dataframe with two columns: company name and tags in a long format. There are a variable number of tags attached to each company, resulting in about 80k rows:
Company Tags
Company A Tag A
Company A Tag B
Company A Tag C
Company B Tag A
Company B Tag B
Company B Tag C
Company B Tag D
Company B Tag E
Company B Tag F
Company C Tag A
Company C Tag B
Company C Tag C
Company C Tag D
I want to turn it into a wide format:
Company Tag 1 Tag 2 Tag 3 Tag 4 Tag 5 Tag 6
Company A Tag A Tag B Tag C
Company B Tag A Tag B Tag C Tag D Tag E Tag F
Company C Tag A Tag B Tag C Tag D
Spread doesn't work, because it's expecting me to pass it a column that will become the column names in wide format, but I don't have one. So I can't spread it as is. It seems like I have two options:
Create another column with numbers attached to each company to serve as column names in wide format. But I don't know how to do that in code for every company.
Find a package with a function that can cast the dataframe wide more flexibly than Spread can. Splitstackshape does this well for turning dataframes into long format, but not the other way around.
Any advice would be appreciated! Also, I'd love to learn how to format these tables better without having to do a bunch of manual tabs/spacing.