English 中文(简体)
R: 在一个时间序列中记录缺失的日期?
原标题:R: Filling missing dates in a time series?

I have a zoo time series with missing days. In order to fill it and have a continuous series I do...

我从一开始即产生时间序列。

我的系列内容与这一系列内容合并。

我用na.locf用激光肥料替代北美人。

我删除了牙齿序列。

Can I do same easier? Maybe with some index function related to the frequency?

问题回答

如果你使用“豁免”<代码>zoo,则稍为容易。 标有指数的物体。

> x <- zoo(1:10,Sys.Date()-10:1)[c(1,3,5,7,10)]
> empty <- zoo(order.by=seq.Date(head(index(x),1),tail(index(x),1),by="days"))
> na.locf(merge(x,empty))
2010-08-14 2010-08-15 2010-08-16 2010-08-17 2010-08-18 
         1          1          3          3          5 
2010-08-19 2010-08-20 2010-08-21 2010-08-22 2010-08-23 
         5          7          7          7         10 

EDIT: For intra-day data (using Gabor s excellent xout= suggestion):

> index(x) <- as.POSIXct(index(x))
> na.locf(x, xout=seq(head(index(x),1),tail(index(x),1),by="15 min"))

http://cran.r-project.org/web/ Packages/zoo/vignettes/zoo-faq.pdf rel=“noreferer” http://cran.r-project.org/web/ Packages/zoo/vignettes/zoo-faq.pdf。 采用Xout=na.locf论点来消除合并步骤。 相信你正在使用1.6.4代乐器,或是在最近添加这一特征之后使用。





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签