【发布时间】:2020-06-10 12:17:58
【问题描述】:
我有一个包含时间戳、状态、类型和值列的 R 数据表
当timestamp为min(一天的第一个),status为1,type为A时,我需要选择值。
我试过了:min(dt$timestamp[dt$status ==1 & dt$type == 'A']$value)
数据表:
timestamp status type value
01-02-2020 08:09:10 1 A 2
01-02-2020 08:19:34 0 A 3
01-02-2020 08:34:10 0 A 4
01-02-2020 09:09:33 0 B 5
01-02-2020 10:09:10 1 B 2
02-02-2020 05:06:11 1 B 3
02-02-2020 08:09:10 1 A 4
02-02-2020 09:02:11 1 A 4
02-02-2020 10:29:15 0 A 6
预期输出:如果我想要日期01-02-2020,那么当status == 0 和type == A 是01-02-2020 08:19:34 时minimum timestamp。对应的值为3
如果我想约会02-02-2020,那么当status == 0 和type == A 是02-02-2020 10:29:15 时minimum timestamp。对应的值为6
我应该能够提供所需的日期。
【问题讨论】:
标签: r data.table