0

我有一个long格式的df。这是一个示例:

       Dates   Names      Point.Forecast
1 2000-03-01 MSCI ACWI     0.16309946
2 2000-04-03 MSCI ACWI     0.21412161
3 2000-05-01 MSCI ACWI     0.04679327
4 2000-03-01 DJGlbl        0.1810070
5 2000-04-03 DJGlbl        0.1293746
6 2000-05-01 DJGlbl        0.7411549
7 2000-03-01 IBOXX         0.2861171
8 2000-04-03 IBOXX         0.25387063
9 2000-05-01 IBOXX         0.29944246

str(df)
'data.frame':   3408 obs. of  3 variables:
 $ Dates         : chr  "2000-03-01" "2000-04-03" "2000-05-01" "2000-06-01" ...
 $ Names         : chr  "MSCI ACWI" "MSCI ACWI" "MSCI ACWI" "MSCI ACWI" ...
 $ Point.Forecast: num  0.1631 0.2141 0.0468 -0.1833 0.252 ...

我想将它转换为wide格式,所以它看起来像:

 Dates        MSCI ACWI      DJGlbl         IBOXX 
2000-03-01    0.16309946     0.21412161     0.04679327
2000-04-03    0.1810070      0.1293746      0.7411549
2000-05-01    0.2861171      0.25387063     0.29944246

我得到一个error

dfd=dcast(df,Dates~Names,value.var="Point.Forecast")

Aggregation function missing: defaulting to length

有什么建议么?

此致

4

0 回答 0