0
我有下面的數據,我需要管理:Organzing /清潔數據幀
data <- data.frame(Name=c("11C","11C","11C","11C","11C","20D","20D"),
PID=c("AD15E","AD15E","AD15E","AA05D","AA05D","Z48J","Z48J"),
Type=c("Home","Auto","Auto","Home","Auto","Auto","Home"),
Brand=c("A","B","C","H","I","P","D"),
Model=c("A152","K235","W54","H2","A57","Z23","Y0878"))
通過獨特的名稱和PID,我想將數據從行轉換成列。 PID「AA05D」有兩個類型「自動」,所以我想第二行被轉換成它自己的列。
我不知道我可以用什麼來實現這一點。
我在尋找清潔的數據如下所示:
result <- data.frame(Name=c("11C","11C","20D"),
PID=c("AD15E","AA05D","Z48J"),
Home.Brand=c("A","H","D"),
Home.Model=c("A152","H2","Y0878"),
Auto1.Brand=c("B","I","P"),
Auto1.Model=c("K235","A57","Z23"),
Auto2.Brand=c("C","",""),
Auto2.Model=c("W54","",""))