0
我有一些數據格式如下。我已經對此進行了一些分析,並希望能夠將分析數據與同一圖表中的價格發展進行比較。 這需要我具有相同的x軸數據。R收集權益數據 - 添加時間和價格
因此,我想彙總「股票」列中的150個增量,並添加「最終價格」和「時間」。 聚合應該包括最新的時間和價格,所以如果聚合需要發生在兩行或更多行數據上,那麼最後一行應該提供價格和時間數據。
我的問題是如何創建一個新的向量與每行150股。 矢量的長度等於總和(份額)/ 150。
有沒有簡單的方法來做到這一點?提前致謝。
編輯: 我想過使用rep(finalprice,shares)擴展觀測值,然後獲取擴展向量的每個第150個值。
數據樣本:
"date","ord","shares","finalprice","time","stock"
20120702,E,2000,99.35,540.84753333,500
20120702,E,28000,99.35,540.84753333,500
20120702,E,50,99.5,542.03073333,500
20120702,E,13874,99.5,542.29411667,500
20120702,E,292,99.5,542.30191667,500
20120702,E,784,99.5,542.30193333,500
20120702,E,13300,99.35,543.04805,500
20120702,E,16658,99.35,543.04805,500
20120702,E,42,99.5,543.04805,500
20120702,E,400,99.4,546.17173333,500
20120702,E,100,99.4,547.07,500
20120702,E,2219,99.3,549.47988333,500
20120702,E,781,99.3,549.5238,500
20120702,E,50,99.3,553.4052,500
20120702,E,1500,99.35,559.86275,500
20120702,E,103,99.5,567.56726667,500
20120702,E,1105,99.7,573.93326667,500
20120702,E,4100,99.5,582.2657,500
20120702,E,900,99.5,582.2657,500
20120702,E,1024,99.45,582.43891667,500
20120702,E,8214,99.45,582.43891667,500
20120702,E,10762,99.45,582.43895,500
20120702,E,1250,99.6,586.86446667,500
20120702,E,5000,99.45,594.39061667,500
20120702,E,20000,99.45,594.39061667,500
20120702,E,15000,99.45,594.39061667,500
20120702,E,4000,99.45,601.34491667,500
20120702,E,8700,99.45,603.53608333,500
20120702,E,3290,99.6,609.23213333,500