【问题标题】:Extracting certain months from a time series in R从R中的时间序列中提取某些月份
【发布时间】:2020-06-23 09:38:00
【问题描述】:

我正在处理气候数据,并拥有从 1974 年到 2012 年的每日温度测量的时间序列。我想将我的时间序列分成 2 个时间序列,其中一个是生长季节(每年 4 月 1 日至 8 月 31 日)和非生长季节(每年 9 月 1 日至 3 月 31 日)。

我的数据如下所示:

[1] 98.9 98.7 100.9 102.4 105.1 106.7 105.9 104.6 103.9 103.8 107.0 108.4 108.0 107.4 110.6 107.3 [17] 106.2 108.7 108.2 106.5 102.3 102.1 107.5 106.5 105.7 103.7 104.8 105.8 105.1 104.6 106.1 106.6 [33] 106.0 103.3 103.1 104.4 102.9 103.0 104.0 109.8 110.5 111.5 107.9 106.1 104.9 105.7 107.1 104.8 [49] 105.7 103.5 101.4 103.1 105.7 105.7 101.7 100.7 102.1 101.4 101.9 101.9 101.4 101.4 101.2 101.2

我该怎么做?

提前致谢

【问题讨论】:

  • 您能否提供reproducible example 以及测量的时间戳 (YY/MM)?
  • 你尝试了什么?如果那是每日数据,那么第一点是“01-01-1974”?如果是,那么您可以找出与您想要的日期相对应的点并过滤...

标签: r filter time-series


【解决方案1】:

类似这样的:

library(tibble)
library(dplyr)
library(lubridate)

climate <- tibble(
  temperature = c(98.9, 98.7, 100.9, 102.4, 105.1, 106.7, 105.9, 104.6, 103.9, 103.8, 107.0, 108.4, 108.0, 107.4, 110.6, 107.3, 106.2, 108.7, 108.2, 106.5, 102.3, 102.1, 107.5, 106.5, 105.7, 103.7, 104.8, 105.8, 105.1, 104.6, 106.1, 106.6, 106.0, 103.3, 103.1, 104.4, 102.9, 103.0, 104.0, 109.8, 110.5, 111.5, 107.9, 106.1, 104.9, 105.7, 107.1, 104.8, 105.7, 103.5, 101.4, 103.1, 105.7, 105.7, 101.7, 100.7, 102.1, 101.4, 101.9, 101.9, 101.4, 101.4, 101.2, 101.2),
  date = seq(as.Date("1974-01-01"), by="1 day", l = length(temperature)),
  month = month(date),
  growing_season = (month %in% (4:8))
)

growing <- climate %>% filter(growing_season)
non_growing <- climate %>% filter(!growing_season)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 2017-06-25
    相关资源
    最近更新 更多