如何通過分組從數據框中獲取修改和未修改的行。R-如何從數據框中檢查修改和未修改的值
數據幀。
U_ID process value1 value2
1 Fetch A A
2 Review C C
1 Review A H
1 Fetch B C
2 Review NA F
3 Fetch A D
4 Fetch R J
4 Review H J
下面數據幀顯示前一行值的樣品通過分組U_ID,工藝塔。
U_ID process value1 value2 value1modified value2modified
1 Fetch A A 0 0
1 Fetch B C 1 1
1 Review A H 0 0
2 Review C C 0 0
2 Review NA F 1 1
3 Fetch A D 0 0
4 Fetch R J 0 0
4 Review H J 0 0
我的預期數據幀。
U_ID process value1modcount value1unmodcount value2modcount value2unmodcount
1 Fetch 1 1 1 1
1 Review 0 1 0 1
2 Review 1 1 1 1
3 Fetch 0 1 0 1
4 Fetch 0 1 0 1
4 Review 0 1 0 1
DATA
structure(list(U_ID = c(1, 2, 1, 1, 2, 3, 4, 4), process = c("Fetch",
"Review", "Review", "Fetch", "Review", "Fetch", "Fetch", "Review"
), value1 = c("A", "C", "A", "B", NA, "A", "R", "H"), value2 = c("A",
"C", "H", "C", "F", "D", "J", "j")), .Names = c("U_ID", "process",
"value1", "value2"), row.names = c(NA, -8L), class = "data.frame")
如何將決定順序?有沒有任何id或時間戳列? –
是的,我們需要爲U_ID申請順序, –
請給予好評和接受的答案,如果它值得 –