R:计算单独样品的测量时间点 [英] R: Calculate measurement time-points for separate samples
问题描述
我在 10 分钟的时间间隔内测量了不同样品(系列)的 N2O 浓度.每个样品每天测量两次,共 9 天.N2O 分析仪每秒保存数据(浓度)!
I have measured concentrations of N2O for different samples (Series) during 10 min intervals. Each sample was measured two times a day for 9 days. The N2O analyzer saved data (conc.) every second!
我的数据现在看起来像这样:
My data now looks like this:
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)
I would like to analyze gas fluxes using the R HMR package. For this, I need to calculate measurement time-points in increasing order out of the exact time (TIME) data points. The time should look like this (table taken from 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.我的机器测量浓度的秒数.每一秒.
How can I calculate this for each individual 10-minute measurement period for each pot? Basically it should list the increasing nr. of seconds as my machine measured conc. every second.
我的想法是按系列"和日期"分组并进行循环.灵感来自 R:计算特定事件之间的时间差类似的东西:
My idea is to group by "Series" and "DATE" and do a loop. Inspired by R: calculate time difference between specific events Something like:
library(dplyr)
df.HMR %>% group_by(DATE, Series) %>%
mutate(time_diff = ????)
非常感谢您的帮助!
推荐答案
使用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))
这篇关于R:计算单独样品的测量时间点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!