I am trying to import time series data in R with the below code. The data is from 1-7-2014
to 30-4-2017
making it 1035 data point. But when I use the below code it gives 1093 observation.
我正在尝试使用以下代码导入R中的时间序列数据。数据从1-7-2014到30-4-2017,使其成为1035数据点。但是,当我使用下面的代码时,它给出了1093观察。
series <- ts(data1, start=c(2014,7,1), end=c(2017,4,30), frequency = 365)
Can someone help me in understanding where am I going wrong?
有人可以帮我理解我哪里出错了吗?
1 个解决方案
#1
2
ts
doesn't allow input for start
and end
in this form. Either a single number or a vector of two integers is allowed. In second case it's year and day number, starting from 1st January.
ts不允许以此形式输入开始和结束。允许单个数字或两个整数的向量。在第二种情况下,它是从1月1日开始的年和日数。
With the help of lubridate
you can use the following. decimal_date
will convert the date to proper integer, suitable for ts
.
在lubridate的帮助下,您可以使用以下内容。 decimal_date会将日期转换为适当的整数,适合ts。
library(lubridate)
series <- ts(data1, start=decimal_date(as.Date("2014-07-01")), end=decimal_date(as.Date("2017-04-30") + 1), frequency = 365)
> length(series)
[1] 1035
#1
2
ts
doesn't allow input for start
and end
in this form. Either a single number or a vector of two integers is allowed. In second case it's year and day number, starting from 1st January.
ts不允许以此形式输入开始和结束。允许单个数字或两个整数的向量。在第二种情况下,它是从1月1日开始的年和日数。
With the help of lubridate
you can use the following. decimal_date
will convert the date to proper integer, suitable for ts
.
在lubridate的帮助下,您可以使用以下内容。 decimal_date会将日期转换为适当的整数,适合ts。
library(lubridate)
series <- ts(data1, start=decimal_date(as.Date("2014-07-01")), end=decimal_date(as.Date("2017-04-30") + 1), frequency = 365)
> length(series)
[1] 1035