R 有没有方法在较低的时间尺度上用信号填充(pad)每月动物园对象?
假设我有一个每月一次的动物园数据序列,其中包含来自集合{0,1}的信号 e、 g 是否有一种巧妙的矢量化方法,用信号值填充月与月之间的每日数据?此外,它还需要滞后移动1。2005年10月第1排也是如此。a、 b,c=c(1,0,1),我想用这个集合{1,0,1}填充整个2005年11月。接下来是2005年11月={0,1,1},整个12月都将填充这些值。。。 一直到第n个月R 有没有方法在较低的时间尺度上用信号填充(pad)每月动物园对象?,r,zoo,lubridate,R,Zoo,Lubridate,假设我有一个每月一次的动物园数据序列,其中包含来自集合{0,1}的信号 e、 g 是否有一种巧妙的矢量化方法,用信号值填充月与月之间的每日数据?此外,它还需要滞后移动1。2005年10月第1排也是如此。a、 b,c=c(1,0,1),我想用这个集合{1,0,1}填充整个2005年11月。接下来是2005年11月={0,1,1},整个12月都将填充这些值。。。 一直到第n个月 我更愿意从每月规模开始生成,但要分析填充的每日值。我在考虑excel中的自动筛选或透视表之类的东西。这实际上相当简单,多亏
我更愿意从每月规模开始生成,但要分析填充的每日值。我在考虑excel中的自动筛选或透视表之类的东西。这实际上相当简单,多亏了zoo。首先,将对象的索引从
yearmon
转换为Date
。然后从该系列的开始到结束生成一个每日日期序列。最后,合并并填充缺少的值
# assuming your monthly series is called 'Z'
# create new object and convert index to Date
z <- Z
index(z) <- as.Date(index(z))
# generate daily sequence
# note that yearmon are converted to the first Date of the month,
# so I add one month and subtract one day from the last yearmon value
dailySeq <- seq(start(z), as.Date(end(Z)+1/12)-1, by="1 day")
# merge z with empty zoo object containing the new daily index
d <- merge(z, zoo(,dailySeq))
# fill in missing values using last-observation-carried-forward
d <- na.locf(d)
#假设您的每月系列名为“Z”
#创建新对象并将索引转换为日期
Z
# assuming your monthly series is called 'Z'
# create new object and convert index to Date
z <- Z
index(z) <- as.Date(index(z))
# generate daily sequence
# note that yearmon are converted to the first Date of the month,
# so I add one month and subtract one day from the last yearmon value
dailySeq <- seq(start(z), as.Date(end(Z)+1/12)-1, by="1 day")
# merge z with empty zoo object containing the new daily index
d <- merge(z, zoo(,dailySeq))
# fill in missing values using last-observation-carried-forward
d <- na.locf(d)