我想传播按TYPE(第1列)分组的数据框,以显示与它们相关联的所有不同DESC。我在R工作;我能找到处理这种情况的最接近的函数是tidyr :: spread,但我不希望每个DESC都有不同的列,只是计数器列。
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)
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)