0
新的數據列使用下面的數據:創建與發生變異
data <- data.frame(Name=c("11C","11C","12C","12C","20D","20D"),
PID=c("AD15E","AD15E","AA05D","AA05D","Z48J","Z48J"),
Type=c("Home","Auto","Home","Auto","Home","Auto"),
Brand=c("A","B","C","H","I","D"),
Model=c("A152","K235","W54","H2","A57","Y0878"))
使用變異,我想在數據幀(HomeBrand,HomeModel,AutoBrand,AutoModel)在該行建立4個新列,其中第一唯一PID顯示。
結果應該如下所示:
result <- data.frame(Name=c("11C","12C","20D"),
PID=c("AD15E","AA05D","Z48J"),
Type=c("Home","Home","Home"),
HomeBrand=c("A","C","I"),
HomeModel=c("A152","W54","A57"),
AutoBrand=c("B","H","D"),
AutoModel=c("K235","H2","Y0878"))
我一直在使用發生變異嘗試,但似乎無法弄清楚