2016-11-14 84 views
1

我有一列日期,从CSV导出到数据框,默认类型在“导入数据集...”“...从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

或者,如果我直接读入与格式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

?read.zoo有关file -parameter:

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()

工作示例:

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')