简体   繁体   English

R的时间序列会自动生成丢失的数据吗?

[英]Does R's Time-Series automatically generate missing data?

I was wondering if anyone with knowledge on R's time-series from the stats package could help me out. 我想知道是否有人从stats软件包中了解R的时间序列可以帮助我。

I'm currently generating a Time-Series using stat's ts function. 我目前正在使用stat的ts函数生成时间序列。

I'm passing the ts function a data set (with 3 years worth of dates and numeric values for each day), the start and end date that have been parsed as a decimal date, and the frequency of 365. However, there are certain ranges of dates missing (for example, dates and values from April 30th, 2016 to January 2nd, 2017 are missing). 我向ts函数传递了一个数据集(每天包含3年的日期和数字值),开始和结束日期(已解析为十进制日期)以及365的频率。但是,日期范围缺失(例如,缺少2016年4月30日至2017年1月2日的日期和值)。

However, when I view or plot the time series, I noticed that the missing data is automatically filled with values. 但是,当我查看或绘制时间序列时,我注意到丢失的数据会自动填充值。

I'm not sure how these values have been generated. 我不确定这些值是如何生成的。

Does the time series function automatically fill in missing dates with their data? 时间序列功能是否会自动使用其数据填写缺失的日期?

Thanks for any help, 谢谢你的帮助,
Jay 周杰伦

Edit: Example of part of my original data frame: 编辑:我原始数据框架的一部分的示例:
(you can see that there are missing data from 2016-04-30 to 2017-01-02) (您会发现从2016-04-30到2017-01-02缺少数据)

 Dataframe:
             date          pieceVolume
 ...   |      ...       |     ...  
 615   |   2016-04-29   |    250.5  
 616   |   2016-04-30   |    1230.4  
 617   |   2017-01-02   |    273.2  
 618   |   2017-01-01   |    26150.5  
 619   |   2017-01-02   |    232550.7  

My original data frame has 655 rows, but my time series has a length of 1079. 我的原始数据帧有655行,但是我的时间序列的长度为1079。
This is how I'm generating my timeseries from the data frame: 这就是我从数据帧生成时间序列的方式:

sts <- ts(test_data$pieceVolume, start=decimal_date(min(as.Date(test_data$date))), end=decimal_date(max(as.Date(test_data$date))), frequency=365)

My Original Code: 我的原始代码:

original_data <- readRDS("original_data.rds")
library(plyr)
## Using ddply to average all the pieceVolumes that have the same dates.
test_data <- plyr::ddply(original_data, .(date), function(x) c(pieceVolume=mean(x$pieceVolume)))
library("forecast")
## Generate time-series using test_data
sts <- ts(test_data$pieceVolume, start=decimal_date(min(as.Date(test_data$date))), end=decimal_date(max(as.Date(test_data$date))), frequency=365)

尝试

sts<- ts(test_data$pieceVolume)

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

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