【发布时间】:2022-10-22 04:46:47
【问题描述】:
我将降水同位素值与降水事件的日期相匹配。样本收集发生在 7-10 天,我想知道有多少样本捕获了一天的降水。我的目标是创建一个包含日期、降水量和同位素值的新数据框。
以下是一些示例数据。数据框展示了我从几个存储库中收集的内容的结构。
# example dates over three week period
start <- as.Date('2017/01/01')
len <- 21
dates <- seq(start, by = "day", length.out = len)
# example precip events in total mm accumulation
prcp <- c(0, 1.0, 2.0, 0, 1.0, 0, 0, # week 1
0, 0, 0, 0, 0, 1.75, 2.0, # week 2
0, 0, 0, 0, 0, 0, 0) # week 3
# sample measurements (numeric)
samp <- c(NA, NA, NA, NA, -15.0, NA, NA,
NA, NA, NA, NA, NA, -12.0, NA,
NA, NA, NA, NA, NA, -20, NA)
# df showing dates, the recorded precip, and the sample measurements
# notice that sample values are associated with collection date
raw <- data.frame(dates, prcp, samp)
在此示例中,有三个样本测量值。
-
第一个 (-15) 对应于第一周的三天降水,应丢弃。
-
第二个样本值 (-12) 对应于一个记录的降水日,应予以保留。样品于2017-01-13采集,雨水于2017-01-13落入采集器。样品采集通常在下午晚些时候进行,所以我假设他们捕获了当天的降水。
-
第三个样本 (-20) 对应于 2017-01-14 发生的降水。它是在 2017 年 1 月 20 日收集的,在 2017 年 1 月 13 日(样本 #2)和 2017 年 1 月 20 日(样本 #3)之间没有其他降雨事件。它也应该保留。
我正在生成的新数据框如下例所示。
# dates when a single precip day occurs between sample collection dates dates_out <- c('2017-01-13', '2017-01-14') # example precip events in total mm accumulation prcp_out <- c(1.75, 2.0) # sample measurements (numeric) samp_out <- c( -12.0, -20) # df showing dates, the recorded precip, and the sample measurements final <- data.frame(dates_out, prcp_out, samp_out)感谢您对我的方法或替代方法和建议的任何帮助!
【问题讨论】:
-
“我想知道有多少样本捕获了一天的降水”澄清一下:您正在寻找捕获一天降水的样本在任何一周内?
-
你好,这与我的意图很接近。目标是将样本采集日期之间发生的单日降水与风暴后采集的样本相匹配。当收集的样本只包含一天的雨水时,我可以使用它们。如果样本桶中有多天下雨,它们的用处就会降低。
标签: r function conditional-statements