2016-11-14 13 views
1

私は日付の列を持っています。これは、ExcelからCSVとしてデータフレームにエクスポートされます。「インポートデータセット」のデフォルトのタイプです。 d<-read_csv(data.csv)。 私は動物園やxtsオブジェクトを作成するのが好きなデータフレームからです。Excelから動物園へ(またはxts)

データは次のとおりです。

30/04/2016 
31/05/2016 
30/06/2016 

私は次のエラーを取得:

dates <- c('30/04/2016','31/05/2016','30/06/2016') 
d <- dates 
z <- read.zoo(d) 

Error in read.zoo(d) : index has bad entry at data row 1

z <- read.zoo(d, FUN = as.Date()) 

Error in as.Date() : argument "x" is missing, with no default

z <- read.zoo(d, FUN = as.Date(format="%d/%m/%Y")) 

Error in as.Date(format = "%d/%m/%Y") : argument "x" is missing, with no default

を0

私は、フォーマットarguemntで動物園に直接読み込む場合は代わりに、私は別のエラーを取得:

ts.z <- read.zoo(d,index=1,tz='',format="%d/%m/%Y") 

Error in read.zoo(d, index = 1, tz = "", format = "%d/%m/%Y") :
index has bad entry at data row 1

を悪いエントリ行が1つのエラーは何ですか? FUN =を指定する正しい方法は何ですか? read.zooの正しい入力クラスと違いは何ですか?

答えて

1
file -parameterについて ?read.zooから

:あなたの例では間違って起こっている

character string or strings giving the name of the file(s) which the data are to be read from/written to. See read.table and write.table for more information. Alternatively, in read.zoo , file can be a connection or a data.frame (e.g., resulting from a previous read.table call) that is subsequently processed to a "zoo" series.

dは、ファイル名、接続またはdata.frameでもないということです。あなたはdata.frame()にそれをラップする必要があります。

A実施例:

z <- read.zoo(data.frame(dates), FUN = as.Date, format='%d/%m/%Y') 

与える:

> z 

2016-04-30 
2016-05-31 
2016-06-30 
> class(z) 
[1] "zoo" 

使用される入力データ:

dates <- c('30/04/2016','31/05/2016','30/06/2016') 
関連する問題