与动物园

时间:2018-03-24 19:12:47

标签: r zoo

您好我要导入一个。在r中的csv文件,我有以下代码:

fbmonthly<-read.zoo("E:\\R\\Stockforecast\\Data\\AAPLmonthly.csv",sep=",",header= TRUE, format = '%m/%Y', FUN=as.Date)

虽然我有这个错误:

  

read.zoo错误(&#34; E:\ R \ Stockforecast \ Data \ AAPLmonthly.csv&#34;,sep =&#34;,&#34;,:     index在数据行中有错误条目:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

我的csv文件看起来像01-03-13 0 0 0 0 0 0 01-04-13 63.128571 63.607143 55.014286 63.254284 47.519821 2740872400 01-05-13 63.494286 66.535713 59.842857 64.247147 48.265705 2361882600 01-06-13 64.389999 64.918571 55.552856 56.647144 44.609531 1754634000 01-07-13 57.527142 65.334282 57.317142 64.647141 50.909512 1634528700 01-08-13 65.10714 73.391426 64.751427 69.602859 54.812115 2014584600 01-09-13 70.442856 72.559998 63.888573 68.10714 56.215424 2157735300 01-10-13 68.349998 77.035713 68.325714 74.671425 61.633572 1959433000 01-11-13 74.860001 79.761429 73.197144 79.438568 65.568352 1306288900 01-12-13 79.714287 82.162857 76.971428 80.145714 68.953758 1764349300 01-01-14 79.382858 80.028572 70.507141 71.514282 61.527653 2191488600 01-02-14 71.80143 78.741432 71.328575 75.177139 64.679031 1470091700 01-03-14 74.774284 78.428574 74.687141 76.677139 68.836685 1250424700 01-04-14 76.822861 85.632858 73.047142 84.298569 75.678795 1608765200 01-05-14 84.571426 92.024284 82.904289 90.428574 81.181992 1433917100 01-06-14 90.565712 95.050003 88.928574 92.93 86.802559 1206934800 01-07-14 93.519997 99.440002 92.57 95.599998 89.296494 1035086000 01-08-14 94.900002 102.900002 93.279999 102.5 95.741524 937077000

你能帮帮我吗? 感谢

3 个答案:

答案 0 :(得分:2)

这不是“CSV”文件。它的分隔符似乎是空格,这是read.zoo默认使用的。没有标头,也是read.zoo的默认标头。需要更正日期格式:

read.zoo(text="01-03-13    0   0   0   0   0   0
 01-04-13    63.128571   63.607143   55.014286   63.254284   47.519821   2740872400", 
 format = '%m-%d-%y')
                 V2       V3       V4       V5       V6         V7
2013-01-03  0.00000  0.00000  0.00000  0.00000  0.00000          0
2013-01-04 63.12857 63.60714 55.01429 63.25428 47.51982 2740872400

答案 1 :(得分:-1)

   fbmonthly<-read.zoo("E:\\R\\Stockforecast\\Data\\AAPLmonthly.csv",sep=",",header= TRUE, format = '%d-%m-%Y', FUN=as.Date)

如果您有标题和逗号分隔文件,则表明您的日期格式错误。

答案 2 :(得分:-1)

所以你说使用fbmonthly<-read.zoo("E:\\R\\Stockforecast\\Data\\AAPLmonthly.csv",sep=".",header= TRUE, format = '%m-%Y', FUN=as.yearmon)

代替?