0
我希望不同組的前一行值。我已經通過了解決方案here,並嘗試了下面顯示的代碼。按組別劃分的R行數值
new_data[,avg_week := shift(.(avg_travel_time),type = "lag"), by = identifier]
這是我得到的錯誤。
Error in `[.data.frame`(new_data, , `:=`(avg_week, c(NA, avg_travel_time[-.N])), :
unused argument (by = identifier)
你有一個錯字之前先轉換爲
data.table
(setDT(new_data)
不需要'(''內'shift' NEW_DATA [,avg_week:=移(avg_travel_time,TYPE =「滯後「),由=標識符]' – akrun還是一樣的錯誤「> NEW_DATA [,avg_week:=移(avg_travel_time,類型= 」滯後「),由=標識符] 錯誤'[.data.frame'(NEW_DATA, ,':='(avg_week,shift(avg_travel_time,: unused argument(by = identifier)' – cutepanda