I'd like to spread my data frame grouped by the TYPE (column 1) to show all the different DESC that are associated with them. I'm working in R; the closest function I can find to handle this situation is tidyr::spread, but I don't want a different column for every single DESC, just counter columns.
Code below creates 2 dataframes that gives an example of what I'd like to convert from and to (mydata -> mydata2)
column1 <- c("color","color","color","size","size")
column2 <- c("red","blue","green","small","big")
mydata <- data.frame(column1,column2)
colnames(mydata)[c(1:2)] <- c("type","desc")
View(mydata)
Convert to:
column1 <- c("color","size")
column2 <- c("red","big")
column3 <- c("green","small")
column4 <- c("blue",NA)
mydata2 <- data.frame(column1,column2,column3,column4)
colnames(mydata2)[c(1:4)] <- c("type","desc1","desc2","desc3","desc4")
View(mydata2)