head(goog.merge)
Date goog.price nasdaq.price
1 0001-10-20 306.7987 21.74104
2 0001-10-20 311.2593 23.32575
3 0001-10-20 370.3703 24.95281
4 0001-10-20 564.5264 37.99543
5 0001-11-20 300.2553 18.79405
6 0001-11-20 307.6978 22.02833
但是当我使用订单功能时:
goog.merge <- goog.merge[order(goog$Date, decreasing = TRUE),]
数据以一种看似无序的方式混乱:
Date goog.price nasdaq.price
100 0001-03-20 361.4742 24.71855
352 <NA> 750.2600 57.56088
604 <NA> 308.8866 24.67877
1105 <NA> 577.2426 36.66454
1358 <NA> 334.2763 21.22208
101 0001-03-20 551.9490 37.86218
这是我用来输入数据的内容:enter code here
goog <- read.table("/Users/bhumphreys/Downloads/Google_closing.csv", header = TRUE, sep = ",")[c("Date","Adj.Close")]
然后我合并了goog和nasdaq(使用相同的方法输入),转换为日期:
goog.merge <- merge(goog, nasdaq, by = "Date")
goog.merge[,c("Date")] <- as.Date(goog.merge[,c("Date")])
我在订购数据时做错了吗?