【发布时间】:2020-06-07 22:17:03
【问题描述】:
这是我的实际数据集的示例:
library("tidyverse")
year <- c(2015,2015,2015,2016,2016,2016,2016)
period <- c("P1","P2","P3","P1","P2","P3","P4")
value <- c(120,130,25,114,236,541,248)
dete <- as.tibble(data.frame(year = year,periode = period, value = value))
所以,在这个数据集中,我们有: 年……年, 期间,就像一个月(相当于 12 周中的 4 周) 价值,例如一些销售价值
我的问题如下: 我想在输出中显示一个像这样向我显示每年的最大值(值)的小标题:
result <- as.tibble(data.frame(period = c("P1","P2","P3","P4"), occurence = c(0,1,1,0)))
但我也想增加权重,在这种情况下,2016 年有 12 个时期中有 4 个时期(一年中有 12 个月),而 2015 年只有 3 个时期。适当的结果是:
result <- as.tibble(data.frame(period = c("P1","P2","P3","P4"), occurence = c(0,3/12,4/12,0)))
通常我有 12 个时期,但有时在去年我只有一部分可用。
【问题讨论】:
标签: r time time-series