在稳定期间汇总变量

时间:2017-06-01 13:33:33

标签: r tidyverse

我是化学研究员,处理数据,其中变量被改变以查看对结果的影响,例如温度升高以查看转换的变化(转换数据未显示)。我想要做的是定义一个函数来获得稳定的'我的数据中的温度区域。以下是data的示例。基于plyr::round_any()lubridate::round_date(),我已经能够使用定义的函数将一些数据作为稳定区域。

library(tidyverse)

all_data <- read_csv("my_data.csv")

trimmed_data <- all_data %>%

  mutate(

    round_temperature = plyr::round_any(Temperature, 0.5),

    round_hours = lubridate::round_date(Date, "12 hour")

  ) %>%

  group_by(round_temperature, round_hours) %>%

  mutate(

    Stable_Lead = if_else(

      round_temperature == lead(round_temperature, 1),

      TRUE, FALSE

    ),

    Stable_Lag  = if_else(

      round_temperature == lag(round_temperature, 1),

      TRUE, FALSE

    ),

    Stable = Stable_Lead + Stable_Lag

  ) %>%

  filter(

    Stable > 0

  ) %>%

  ungroup %>%

  select(-round_temperature, -contains("Stable"), -round_hours)

这都是计划好的,并且删除了一些不必要的数据增加或减少。我接下来要做的是总结一下,或者稍后用线性函数对其进行建模。

我现在的问题是,如何使用group_by()对整个&#39;稳定&#39;进行分组。区域?在这个例子中,我希望整个时间区域在大约130到438小时之间成为稳定区域之一。即使在我的版本中,情况并非如此,我希望有这样一个稳定的区域定义。在这种情况下,似乎有4个稳定的&#39;区域。

这是手工完成的'stable' data

0 个答案:

没有答案