在10年每日时间序列数据中的日期不连续处插入行

时间:2018-11-02 11:02:00

标签: r excel

我有10年的每日温度数据作为每天的一个值。 我有日列和温度列。在“天”列中,每天的日期都写为例如2008001(即2008年的第一天),2008002、2008003 ____,2017365。在3653天中,我有3599天的数据。 我没有有关失踪日子的任何信息。我想要某种类似的方式,在没有一天的地方插入一行,以便我有一个连续的时间序列而没有一天。 我如何在R或Excel中做到这一点。

2 个答案:

答案 0 :(得分:1)

请查看图片以进行说明:

enter image description here

我将从您的日期代码计算实际日期开始。 通过以下方式获得年份:

LEFT($A3,4)

然后我们可以通过以下方式获得上一年的最后一天:

DATE(LEFT($A3,4),1,1)-1

然后只需添加一年中的某天,我们就可以得到:

RIGHT($A3,3)

现在,我们可以为您所需范围内的所有日期创建一个新的单独列表,并使用INDEX / MATCH从原始表中查找值:

enter image description here

=IFNA(INDEX($B$3:$B$17,MATCH($E3,$C$3:$C$17,0)),"")

IFNA只是将#N / A更改为空白单元格(原始数据中没有记录)。

答案 1 :(得分:0)

require('lubridate')
seq(ymd('2008-01-01'), ymd('2017-12-31'), by = 'days')

输出:

   [1] "2008-01-01" "2008-01-02" "2008-01-03" "2008-01-04" "2008-01-05"
   [6] "2008-01-06" "2008-01-07" "2008-01-08" "2008-01-09" "2008-01-10"
  [11] "2008-01-11" "2008-01-12" "2008-01-13" "2008-01-14" "2008-01-15"
  [16] "2008-01-16" "2008-01-17" "2008-01-18" "2008-01-19" "2008-01-20"
  [21] "2008-01-21" "2008-01-22" "2008-01-23" "2008-01-24" "2008-01-25"
  [26] "2008-01-26" "2008-01-27" "2008-01-28" "2008-01-29" "2008-01-30"
  [31] "2008-01-31" "2008-02-01" "2008-02-02" "2008-02-03" "2008-02-04"
  [36] "2008-02-05" "2008-02-06" "2008-02-07" "2008-02-08" "2008-02-09"
  [41] "2008-02-10" "2008-02-11" "2008-02-12" "2008-02-13" "2008-02-14"
  [46] "2008-02-15" "2008-02-16" "2008-02-17" "2008-02-18" "2008-02-19"
  [51] "2008-02-20" "2008-02-21" "2008-02-22" "2008-02-23" "2008-02-24"
  [56] "2008-02-25" "2008-02-26" "2008-02-27" "2008-02-28" "2008-02-29"
  [61] "2008-03-01" "2008-03-02" "2008-03-03" "2008-03-04" "2008-03-05"
  [66] "2008-03-06" "2008-03-07" "2008-03-08" "2008-03-09" "2008-03-10"
  [71] "2008-03-11" "2008-03-12" "2008-03-13" "2008-03-14" "2008-03-15"
  [76] "2008-03-16" "2008-03-17" "2008-03-18" "2008-03-19" "2008-03-20"
  [81] "2008-03-21" "2008-03-22" "2008-03-23" "2008-03-24" "2008-03-25"
  [86] "2008-03-26" "2008-03-27" "2008-03-28" "2008-03-29" "2008-03-30"
  [91] "2008-03-31" "2008-04-01" "2008-04-02" "2008-04-03" "2008-04-04"
  [96] "2008-04-05" "2008-04-06" "2008-04-07" "2008-04-08" "2008-04-09"
 [101] "2008-04-10" "2008-04-11" "2008-04-12" "2008-04-13" "2008-04-14"
 [106] "2008-04-15" "2008-04-16" "2008-04-17" "2008-04-18" "2008-04-19"
 [111] "2008-04-20" "2008-04-21" "2008-04-22" "2008-04-23" "2008-04-24"
 [116] "2008-04-25" "2008-04-26" "2008-04-27" "2008-04-28" "2008-04-29"
 [121] "2008-04-30" "2008-05-01" "2008-05-02" "2008-05-03" "2008-05-04"
 [126] "2008-05-05" "2008-05-06" "2008-05-07" "2008-05-08" "2008-05-09"
 [131] "2008-05-10" "2008-05-11" "2008-05-12" "2008-05-13" "2008-05-14"
 [136] "2008-05-15" "2008-05-16" "2008-05-17" "2008-05-18" "2008-05-19"
 [141] "2008-05-20" "2008-05-21" "2008-05-22" "2008-05-23" "2008-05-24"
 [146] "2008-05-25" "2008-05-26" "2008-05-27" "2008-05-28" "2008-05-29"
 [151] "2008-05-30" "2008-05-31" "2008-06-01" "2008-06-02" "2008-06-03"
 [156] "2008-06-04" "2008-06-05" "2008-06-06" "2008-06-07" "2008-06-08"
 [161] "2008-06-09" "2008-06-10" "2008-06-11" "2008-06-12" "2008-06-13"
 [166] "2008-06-14" "2008-06-15" "2008-06-16" "2008-06-17" "2008-06-18"
 [171] "2008-06-19" "2008-06-20" "2008-06-21" "2008-06-22" "2008-06-23"
 [176] "2008-06-24" "2008-06-25" "2008-06-26" "2008-06-27" "2008-06-28"
 [181] "2008-06-29" "2008-06-30" "2008-07-01" "2008-07-02" "2008-07-03"
 [186] "2008-07-04" "2008-07-05" "2008-07-06" "2008-07-07" "2008-07-08"
 [191] "2008-07-09" "2008-07-10" "2008-07-11" "2008-07-12" "2008-07-13"
 [196] "2008-07-14" "2008-07-15" "2008-07-16" "2008-07-17" "2008-07-18"
 [201] "2008-07-19" "2008-07-20" "2008-07-21" "2008-07-22" "2008-07-23"
 [206] "2008-07-24" "2008-07-25" "2008-07-26" "2008-07-27" "2008-07-28"
 [211] "2008-07-29" "2008-07-30" "2008-07-31" "2008-08-01" "2008-08-02"
 [216] "2008-08-03" "2008-08-04" "2008-08-05" "2008-08-06" "2008-08-07"
 [221] "2008-08-08" "2008-08-09" "2008-08-10" "2008-08-11" "2008-08-12"
 [226] "2008-08-13" "2008-08-14" "2008-08-15" "2008-08-16" "2008-08-17"
 [231] "2008-08-18" "2008-08-19" "2008-08-20" "2008-08-21" "2008-08-22"
 [236] "2008-08-23" "2008-08-24" "2008-08-25" "2008-08-26" "2008-08-27"
 [241] "2008-08-28" "2008-08-29" "2008-08-30" "2008-08-31" "2008-09-01"
 [246] "2008-09-02" "2008-09-03" "2008-09-04" "2008-09-05" "2008-09-06"
 [251] "2008-09-07" "2008-09-08" "2008-09-09" "2008-09-10" "2008-09-11"
 [256] "2008-09-12" "2008-09-13" "2008-09-14" "2008-09-15" "2008-09-16"
 [261] "2008-09-17" "2008-09-18" "2008-09-19" "2008-09-20" "2008-09-21"
 [266] "2008-09-22" "2008-09-23" "2008-09-24" "2008-09-25" "2008-09-26"
 [271] "2008-09-27" "2008-09-28" "2008-09-29" "2008-09-30" "2008-10-01"
 [276] "2008-10-02" "2008-10-03" "2008-10-04" "2008-10-05" "2008-10-06"
 [281] "2008-10-07" "2008-10-08" "2008-10-09" "2008-10-10" "2008-10-11"
 [286] "2008-10-12" "2008-10-13" "2008-10-14" "2008-10-15" "2008-10-16"
 [291] "2008-10-17" "2008-10-18" "2008-10-19" "2008-10-20" "2008-10-21"
 [296] "2008-10-22" "2008-10-23" "2008-10-24" "2008-10-25" "2008-10-26"
 [301] "2008-10-27" "2008-10-28" "2008-10-29" "2008-10-30" "2008-10-31"
 [306] "2008-11-01" "2008-11-02" "2008-11-03" "2008-11-04" "2008-11-05"
 [311] "2008-11-06" "2008-11-07" "2008-11-08" "2008-11-09" "2008-11-10"
 [316] "2008-11-11" "2008-11-12" "2008-11-13" "2008-11-14" "2008-11-15"
 [321] "2008-11-16" "2008-11-17" "2008-11-18" "2008-11-19" "2008-11-20"
 [326] "2008-11-21" "2008-11-22" "2008-11-23" "2008-11-24" "2008-11-25"
 [331] "2008-11-26" "2008-11-27" "2008-11-28" "2008-11-29" "2008-11-30"
 [336] "2008-12-01" "2008-12-02" "2008-12-03" "2008-12-04" "2008-12-05"
 [341] "2008-12-06" "2008-12-07" "2008-12-08" "2008-12-09" "2008-12-10"
 [346] "2008-12-11" "2008-12-12" "2008-12-13" "2008-12-14" "2008-12-15"
 [351] "2008-12-16" "2008-12-17" "2008-12-18" "2008-12-19" "2008-12-20"
 [356] "2008-12-21" "2008-12-22" "2008-12-23" "2008-12-24" "2008-12-25"
 [361] "2008-12-26" "2008-12-27" "2008-12-28" "2008-12-29" "2008-12-30"
 [366] "2008-12-31" "2009-01-01" "2009-01-02" "2009-01-03" "2009-01-04"
 [371] "2009-01-05" "2009-01-06" "2009-01-07" "2009-01-08" "2009-01-09"
 [376] "2009-01-10" "2009-01-11" "2009-01-12" "2009-01-13" "2009-01-14"
 [381] "2009-01-15" "2009-01-16" "2009-01-17" "2009-01-18" "2009-01-19"
 [386] "2009-01-20" "2009-01-21" "2009-01-22" "2009-01-23" "2009-01-24"
 [391] "2009-01-25" "2009-01-26" "2009-01-27" "2009-01-28" "2009-01-29"
 [396] "2009-01-30" "2009-01-31" "2009-02-01" "2009-02-02" "2009-02-03"
 [401] "2009-02-04" "2009-02-05" "2009-02-06" "2009-02-07" "2009-02-08"
 [406] "2009-02-09" "2009-02-10" "2009-02-11" "2009-02-12" "2009-02-13"
 [411] "2009-02-14" "2009-02-15" "2009-02-16" "2009-02-17" "2009-02-18"
 [416] "2009-02-19" "2009-02-20" "2009-02-21" "2009-02-22" "2009-02-23"
 [421] "2009-02-24" "2009-02-25" "2009-02-26" "2009-02-27" "2009-02-28"
 [426] "2009-03-01" "2009-03-02" "2009-03-03" "2009-03-04" "2009-03-05"
 [431] "2009-03-06" "2009-03-07" "2009-03-08" "2009-03-09" "2009-03-10"
 [436] "2009-03-11" "2009-03-12" "2009-03-13" "2009-03-14" "2009-03-15"
 [441] "2009-03-16" "2009-03-17" "2009-03-18" "2009-03-19" "2009-03-20"
 [446] "2009-03-21" "2009-03-22" "2009-03-23" "2009-03-24" "2009-03-25"
 [451] "2009-03-26" "2009-03-27" "2009-03-28" "2009-03-29" "2009-03-30"
 [456] "2009-03-31" "2009-04-01" "2009-04-02" "2009-04-03" "2009-04-04"
 [461] "2009-04-05" "2009-04-06" "2009-04-07" "2009-04-08" "2009-04-09"
 [466] "2009-04-10" "2009-04-11" "2009-04-12" "2009-04-13" "2009-04-14"
 [471] "2009-04-15" "2009-04-16" "2009-04-17" "2009-04-18" "2009-04-19"
 [476] "2009-04-20" "2009-04-21" "2009-04-22" "2009-04-23" "2009-04-24"
 [481] "2009-04-25" "2009-04-26" "2009-04-27" "2009-04-28" "2009-04-29"
 [486] "2009-04-30" "2009-05-01" "2009-05-02" "2009-05-03" "2009-05-04"
 [491] "2009-05-05" "2009-05-06" "2009-05-07" "2009-05-08" "2009-05-09"
 [496] "2009-05-10" "2009-05-11" "2009-05-12" "2009-05-13" "2009-05-14"
 [501] "2009-05-15" "2009-05-16" "2009-05-17" "2009-05-18" "2009-05-19"
 [506] "2009-05-20" "2009-05-21" "2009-05-22" "2009-05-23" "2009-05-24"
 [511] "2009-05-25" "2009-05-26" "2009-05-27" "2009-05-28" "2009-05-29"
 [516] "2009-05-30" "2009-05-31" "2009-06-01" "2009-06-02" "2009-06-03"
 [521] "2009-06-04" "2009-06-05" "2009-06-06" "2009-06-07" "2009-06-08"
 [526] "2009-06-09" "2009-06-10" "2009-06-11" "2009-06-12" "2009-06-13"
 [531] "2009-06-14" "2009-06-15" "2009-06-16" "2009-06-17" "2009-06-18"
 [536] "2009-06-19" "2009-06-20" "2009-06-21" "2009-06-22" "2009-06-23"
 [541] "2009-06-24" "2009-06-25" "2009-06-26" "2009-06-27" "2009-06-28"
 [546] "2009-06-29" "2009-06-30" "2009-07-01" "2009-07-02" "2009-07-03"
 [551] "2009-07-04" "2009-07-05" "2009-07-06" "2009-07-07" "2009-07-08"
 [556] "2009-07-09" "2009-07-10" "2009-07-11" "2009-07-12" "2009-07-13"
 [561] "2009-07-14" "2009-07-15" "2009-07-16" "2009-07-17" "2009-07-18"
 [566] "2009-07-19" "2009-07-20" "2009-07-21" "2009-07-22" "2009-07-23"
 [571] "2009-07-24" "2009-07-25" "2009-07-26" "2009-07-27" "2009-07-28"
 [576] "2009-07-29" "2009-07-30" "2009-07-31" "2009-08-01" "2009-08-02"
 [581] "2009-08-03" "2009-08-04" "2009-08-05" "2009-08-06" "2009-08-07"
 [586] "2009-08-08" "2009-08-09" "2009-08-10" "2009-08-11" "2009-08-12"
 [591] "2009-08-13" "2009-08-14" "2009-08-15" "2009-08-16" "2009-08-17"
 [596] "2009-08-18" "2009-08-19" "2009-08-20" "2009-08-21" "2009-08-22"
 [601] "2009-08-23" "2009-08-24" "2009-08-25" "2009-08-26" "2009-08-27"
 [606] "2009-08-28" "2009-08-29" "2009-08-30" "2009-08-31" "2009-09-01"
 [611] "2009-09-02" "2009-09-03" "2009-09-04" "2009-09-05" "2009-09-06"
 [616] "2009-09-07" "2009-09-08" "2009-09-09" "2009-09-10" "2009-09-11"
 [621] "2009-09-12" "2009-09-13" "2009-09-14" "2009-09-15" "2009-09-16"
 [626] "2009-09-17" "2009-09-18" "2009-09-19" "2009-09-20" "2009-09-21"
 [631] "2009-09-22" "2009-09-23" "2009-09-24" "2009-09-25" "2009-09-26"
 [636] "2009-09-27" "2009-09-28" "2009-09-29" "2009-09-30" "2009-10-01"
 [641] "2009-10-02" "2009-10-03" "2009-10-04" "2009-10-05" "2009-10-06"
 [646] "2009-10-07" "2009-10-08" "2009-10-09" "2009-10-10" "2009-10-11"
 [651] "2009-10-12" "2009-10-13" "2009-10-14" "2009-10-15" "2009-10-16"
 [656] "2009-10-17" "2009-10-18" "2009-10-19" "2009-10-20" "2009-10-21"
 [661] "2009-10-22" "2009-10-23" "2009-10-24" "2009-10-25" "2009-10-26"
 [666] "2009-10-27" "2009-10-28" "2009-10-29" "2009-10-30" "2009-10-31"
 [671] "2009-11-01" "2009-11-02" "2009-11-03" "2009-11-04" "2009-11-05"
 [676] "2009-11-06" "2009-11-07" "2009-11-08" "2009-11-09" "2009-11-10"
 [681] "2009-11-11" "2009-11-12" "2009-11-13" "2009-11-14" "2009-11-15"
 [686] "2009-11-16" "2009-11-17" "2009-11-18" "2009-11-19" "2009-11-20"
 [691] "2009-11-21" "2009-11-22" "2009-11-23" "2009-11-24" "2009-11-25"
 [696] "2009-11-26" "2009-11-27" "2009-11-28" "2009-11-29" "2009-11-30"
 [701] "2009-12-01" "2009-12-02" "2009-12-03" "2009-12-04" "2009-12-05"
 [706] "2009-12-06" "2009-12-07" "2009-12-08" "2009-12-09" "2009-12-10"
 [711] "2009-12-11" "2009-12-12" "2009-12-13" "2009-12-14" "2009-12-15"
 [716] "2009-12-16" "2009-12-17" "2009-12-18" "2009-12-19" "2009-12-20"
 [721] "2009-12-21" "2009-12-22" "2009-12-23" "2009-12-24" "2009-12-25"
 [726] "2009-12-26" "2009-12-27" "2009-12-28" "2009-12-29" "2009-12-30"
 [731] "2009-12-31" "2010-01-01" "2010-01-02" "2010-01-03" "2010-01-04"
 [736] "2010-01-05" "2010-01-06" "2010-01-07" "2010-01-08" "2010-01-09"
 [741] "2010-01-10" "2010-01-11" "2010-01-12" "2010-01-13" "2010-01-14"
 [746] "2010-01-15" "2010-01-16" "2010-01-17" "2010-01-18" "2010-01-19"
 [751] "2010-01-20" "2010-01-21" "2010-01-22" "2010-01-23" "2010-01-24"
 [756] "2010-01-25" "2010-01-26" "2010-01-27" "2010-01-28" "2010-01-29"
 [761] "2010-01-30" "2010-01-31" "2010-02-01" "2010-02-02" "2010-02-03"
 [766] "2010-02-04" "2010-02-05" "2010-02-06" "2010-02-07" "2010-02-08"
 [771] "2010-02-09" "2010-02-10" "2010-02-11" "2010-02-12" "2010-02-13"
 [776] "2010-02-14" "2010-02-15" "2010-02-16" "2010-02-17" "2010-02-18"
 [781] "2010-02-19" "2010-02-20" "2010-02-21" "2010-02-22" "2010-02-23"
 [786] "2010-02-24" "2010-02-25" "2010-02-26" "2010-02-27" "2010-02-28"
 [791] "2010-03-01" "2010-03-02" "2010-03-03" "2010-03-04" "2010-03-05"
 [796] "2010-03-06" "2010-03-07" "2010-03-08" "2010-03-09" "2010-03-10"
 [801] "2010-03-11" "2010-03-12" "2010-03-13" "2010-03-14" "2010-03-15"
 [806] "2010-03-16" "2010-03-17" "2010-03-18" "2010-03-19" "2010-03-20"
 [811] "2010-03-21" "2010-03-22" "2010-03-23" "2010-03-24" "2010-03-25"
 [816] "2010-03-26" "2010-03-27" "2010-03-28" "2010-03-29" "2010-03-30"
 [821] "2010-03-31" "2010-04-01" "2010-04-02" "2010-04-03" "2010-04-04"
 [826] "2010-04-05" "2010-04-06" "2010-04-07" "2010-04-08" "2010-04-09"
 [831] "2010-04-10" "2010-04-11" "2010-04-12" "2010-04-13" "2010-04-14"
 [836] "2010-04-15" "2010-04-16" "2010-04-17" "2010-04-18" "2010-04-19"
 [841] "2010-04-20" "2010-04-21" "2010-04-22" "2010-04-23" "2010-04-24"
 [846] "2010-04-25" "2010-04-26" "2010-04-27" "2010-04-28" "2010-04-29"
 [851] "2010-04-30" "2010-05-01" "2010-05-02" "2010-05-03" "2010-05-04"
 [856] "2010-05-05" "2010-05-06" "2010-05-07" "2010-05-08" "2010-05-09"
 [861] "2010-05-10" "2010-05-11" "2010-05-12" "2010-05-13" "2010-05-14"
 [866] "2010-05-15" "2010-05-16" "2010-05-17" "2010-05-18" "2010-05-19"
 [871] "2010-05-20" "2010-05-21" "2010-05-22" "2010-05-23" "2010-05-24"
 [876] "2010-05-25" "2010-05-26" "2010-05-27" "2010-05-28" "2010-05-29"
 [881] "2010-05-30" "2010-05-31" "2010-06-01" "2010-06-02" "2010-06-03"
 [886] "2010-06-04" "2010-06-05" "2010-06-06" "2010-06-07" "2010-06-08"
 [891] "2010-06-09" "2010-06-10" "2010-06-11" "2010-06-12" "2010-06-13"
 [896] "2010-06-14" "2010-06-15" "2010-06-16" "2010-06-17" "2010-06-18"
 [901] "2010-06-19" "2010-06-20" "2010-06-21" "2010-06-22" "2010-06-23"
 [906] "2010-06-24" "2010-06-25" "2010-06-26" "2010-06-27" "2010-06-28"
 [911] "2010-06-29" "2010-06-30" "2010-07-01" "2010-07-02" "2010-07-03"
 [916] "2010-07-04" "2010-07-05" "2010-07-06" "2010-07-07" "2010-07-08"
 [921] "2010-07-09" "2010-07-10" "2010-07-11" "2010-07-12" "2010-07-13"
 [926] "2010-07-14" "2010-07-15" "2010-07-16" "2010-07-17" "2010-07-18"
 [931] "2010-07-19" "2010-07-20" "2010-07-21" "2010-07-22" "2010-07-23"
 [936] "2010-07-24" "2010-07-25" "2010-07-26" "2010-07-27" "2010-07-28"
 [941] "2010-07-29" "2010-07-30" "2010-07-31" "2010-08-01" "2010-08-02"
 [946] "2010-08-03" "2010-08-04" "2010-08-05" "2010-08-06" "2010-08-07"
 [951] "2010-08-08" "2010-08-09" "2010-08-10" "2010-08-11" "2010-08-12"
 [956] "2010-08-13" "2010-08-14" "2010-08-15" "2010-08-16" "2010-08-17"
 [961] "2010-08-18" "2010-08-19" "2010-08-20" "2010-08-21" "2010-08-22"
 [966] "2010-08-23" "2010-08-24" "2010-08-25" "2010-08-26" "2010-08-27"
 [971] "2010-08-28" "2010-08-29" "2010-08-30" "2010-08-31" "2010-09-01"
 [976] "2010-09-02" "2010-09-03" "2010-09-04" "2010-09-05" "2010-09-06"
 [981] "2010-09-07" "2010-09-08" "2010-09-09" "2010-09-10" "2010-09-11"
 [986] "2010-09-12" "2010-09-13" "2010-09-14" "2010-09-15" "2010-09-16"
 [991] "2010-09-17" "2010-09-18" "2010-09-19" "2010-09-20" "2010-09-21"
 [996] "2010-09-22" "2010-09-23" "2010-09-24" "2010-09-25" "2010-09-26"
 [ reached getOption("max.print") -- omitted 2653 entries ]

顺便说一句,您可以在Excel上安装RExcel加载项以调用R编程。