我有一个数据表df
field_pointpath | timestamp | Value | value1
:-------------: | :-------: | :----:| :----:
6kfs_A0 | 2017-05-01 00:04:00 | 10 | NA
6kfs_A0 | 2017-05-01 00:34:00 | 20 | NA
6kfs_A0 | 2017-05-01 01:34:00 | 40 | NA
6kfs_B0 | 2017-05-01 00:40:00 | 10 | NA
8kfs_A0 | 2017-05-01 00:40:00 | 5 | NA
8kfs_A0 | 2017-05-01 00:46:00 | 15 | NA
8kfs_B0 | 2017-05-01 00:40:00 | 5 | NA
8kfs_B0 | 2017-05-01 01:40:00 | 30 | NA
现在我想创建一个这样的函数
if df$field_pointpath = 6kfs_A0
具有最早的时间戳,其值应替换为零(df$value1 = 0)
再次功能应该在下一行中应用以下条件
if df$field_pointpath = 6kfs_A0 than df$value1 = abs(df[2,3] - df[1,3] + df[1,4])
因此结果应为
field_pointpath | timestamp | Value | value1
:-------------: | :-------: | :----:| :----:
6kfs_A0 | 2017-05-01 00:04:00 | 10 | 0
6kfs_A0 | 2017-05-01 00:34:00 | 20 | 10
6kfs_A0 | 2017-05-01 01:34:00 | 40 | 30
6kfs_B0 | 2017-05-01 00:40:00 | 10 | 0
8kfs_A0 | 2017-05-01 00:40:00 | 5 | 0
8kfs_A0 | 2017-05-01 00:46:00 | 15 | 10
8kfs_B0 | 2017-05-01 00:40:00 | 5 | 0
8kfs_B0 | 2017-05-01 01:40:00 | 30 | 25