简体   繁体   English

可以使用read.zoo()从R中的html读取未索引的时间序列吗?

[英]Possible to use read.zoo() to read an unindexed time series from html in R?

I'm looking to take a data series like the one contained here: 我正在寻找像此处包含的数据系列:

http://robjhyndman.com/tsdldata/roberts/beards.dat http://robjhyndman.com/tsdldata/roberts/beards.dat

...and load it into a zoo time series object in R. There is no table of date information, but it lists that it's regular, annual, and starts in y=1866. ...并将其加载到R中的动物园时间序列对象中。没有日期信息表,但它列出了它是常规的,年度的,并且以y = 1866开始。 This is what I'm attempting... 这就是我正在尝试的...

beard <- read.zoo('http://robjhyndman.com/tsdldata/roberts/beards.dat', 
header=FALSE, 
index.column=0,
start="1866-01-01",
format="%Y", 
skip=4)

It mostly works, but ignores the "start" argument from zooreg. 它通常有效,但是忽略了Zooreg的“开始”参数。

So, I have a fine solution that reads this, then changes the index like so... 因此,我有一个很好的解决方案,可以读取此内容,然后像这样更改索引...

index(beard) <- as.Date(paste(seq(1866,1911, by=1),'-01-01',sep=''), format="%Y-%m-%d")

...but this would be slicker if there were an argument in read.zoo() that let me do this in a single call. ...但是如果read.zoo()中有一个参数可以让我在单个调用中执行此操作,这将是很read.zoo() Am I missing it, or is it a two-step problem? 我是否想念它,还是有两个步骤的问题?

Specify a custom FUN= like this: 指定一个自定义的FUN=如下所示:

URL <- 'http://robjhyndman.com/tsdldata/roberts/beards.dat'
toDate <- function(x) as.Date(as.yearmon(x) + 1865)
beard <- read.zoo(URL, index = 0, skip = 4, FUN = toDate)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM