3
我目前有一個數據幀是從事件按時間順序發生的數據饋送中獲取的。我想到相當於增加一個新的列到我的每行數據的下一個事件的player_id如果事件類型爲1 &結果是1如果行上的語句r
如
player_id <- c(12, 17, 26, 3)
event_type <- c(1, 3, 1, 10)
outcome <- c(1, 0, 1, 1)
df <- data.frame(player_id, event_type, outcome)
df
player_id event_type outcome
1 12 1 1
2 17 3 0
3 26 1 1
4 3 10 1
所以最終的結果
player_id event_type outcome next_player_id
1 12 1 1 17
2 17 3 0 NA
3 26 1 1 3
4 3 10 1 NA
幫助畝CH讚賞,因爲我仍然在初學者中R擋位