我的数据现在看起来像这样:
DATE Series V A TIME Concentration
1: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:00.746 0.3512232
2: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:01.382 0.3498687
3: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:02.124 0.3482681
4: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:03.216 0.3459306
5: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:04.009 0.3459124
6: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:04.326 0.3456660
我想使用R HMR软件包分析气体通量。为此,我需要从准确时间(TIME)数据点中按升序计算测量时间点。 时间应该像这样(表取自https://cran.r-project.org/web/packages/HMR/HMR.pdf)
Series;V;A;Time;Concentration
k0a; 140.6250; 0.5625; 0; 13.98
k0a; 140.6250; 0.5625; 10; 14.65
k0a; 140.6250; 0.5625; 20; 15.15
k0a; 140.6250; 0.5625; 30; 15.85
我如何在每个锅的每个单独的10分钟测量期内计算这个?基本上,它应该列出递增的nr。我的机器测得的浓度为秒每一秒。
我的想法是按“系列”和“日期”分组并进行循环。受R: calculate time difference between specific events的启发 像这样:
library(dplyr)
df.HMR %>% group_by(DATE, Series) %>%
mutate(time_diff = ????)
非常感谢您的帮助!
答案 0 :(得分:0)
使用lag
可以解决问题。
df.HMR=read.table(text="No DATE Series V A TIME Concentration
1: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:00.746 0.3512232
2: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:01.382 0.3498687
3: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:02.124 0.3482681
4: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:03.216 0.3459306
5: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:04.009 0.3459124
6: 2017-10-18T00:00:00Z O11 0.004022 0.02011 10:16:04.326 0.3456660",
header=T,stringsAsFactors=FALSE)
df.HMR %>% group_by(DATE, Series) %>%
mutate(dt=as.POSIXct(df.HMR$TIME,format="%H:%M:%S"), time_diff = dt-lag(dt))