【发布时间】:2019-07-23 00:51:43
【问题描述】:
谁能帮我弄清楚如何根据我的每月数据计算价值差异?例如,我想计算每口井每年 1 月至 7 月、2 月至 8 月、3 月至 9 月等之间的地下水值差异。请注意,在某些年份会缺少几个月。任何tidyverse 解决方案将不胜感激。
Well year month value
<dbl> <dbl> <fct> <dbl>
1 222 1995 February 8.53
2 222 1995 March 8.69
3 222 1995 April 8.92
4 222 1995 May 9.59
5 222 1995 June 9.59
6 222 1995 July 9.70
7 222 1995 August 9.66
8 222 1995 September 9.46
9 222 1995 October 9.49
10 222 1995 November 9.31
# ... with 18,400 more rows
df1 <- subset(df, month %in% c("February", "August"))
test <- df1 %>%
dcast(site + year + Well ~ month, value.var = "value") %>%
mutate(Diff = February - August)
谢谢,
西蒙
【问题讨论】:
-
你试过什么公式?您应该发布 R 代码以生成示例数据。不要包含任何与您的问题无关的数据。
-
请使用
dput提供数据样本。另外,请具体说明您要计算的内容。 -
哇你们这么快
标签: r group-by tidyverse dplyr