我有以下数据框:
id<-c(1,2,3,4,1,1,2,3,4,4,2,2)
period<-c("first","calib","valid","valid","calib","first","valid","valid","calib","first","calib","valid")
df<-data.frame(id,period)
打字
table(df)
结果是
period
id calib first valid
1 1 2 0
2 2 0 2
3 0 0 2
4 1 1 1
有没有办法使用“dcast”获得相同的结果并将其保存为新的数据框?