我的數據是這樣的:R於前述行比較值
Incident.ID.. = c(rep("INCFI0000029582",4), rep("INCFI0000029587",4))
date = c("2014-09-25 08:39:45", "2014-09-25 08:39:48", "2014-09-25 08:40:44", "2014-10-10 23:04:00", "2014-09-25 08:33:32", "2014-09-25 08:34:41", "2014-09-25 08:35:24", "2014-10-10 23:04:00")
status = c("assigned", "in.progress", "resolved", "closed", "assigned", "resolved", "resolved", "closed")
date.diff=c (3, 56, 1347796,0 ,69 ,43, 1348116, 0)
df = data.frame(Incident.ID..,date, status, date.diff, stringsAsFactors = FALSE)
df
Incident.ID.. date status date.diff
1 INCFI0000029582 2014-09-25 08:39:45 assigned 3
2 INCFI0000029582 2014-09-25 08:39:48 in.progress 56
3 INCFI0000029582 2014-09-25 08:40:44 resolved 1347796
4 INCFI0000029582 2014-10-10 23:04:00 closed 0
5 INCFI0000029587 2014-09-25 08:33:32 assigned 69
6 INCFI0000029587 2014-09-25 08:34:41 resolved 43
7 INCFI0000029587 2014-09-25 08:35:24 resolved 1348116
8 INCFI0000029587 2014-10-10 23:04:00 closed 0
而且我想只挑選狀態爲「已解決」的行一定Incident.ID ..當它的後面沒有同一Incident.ID ..的狀態「關閉」(可能只有「已解決」或只有「關閉」 - 行的行,所以這就是爲什麼Incident.ID ..必須在進行比較時相同)。
例如這裏在這個例子中的數據,僅此行將被拾起:
6 INCFI0000029587 2014-09-25 08:34:41 resolved 43
所以我怎麼可能請做到這一點?
@ElinaJ,您需要安裝並加載包dplyr。試試'install.packages(「dplyr」);庫(dplyr)' –