5
Membuat kolom baru secara kondisional berdasarkan pada n baris sebelumnya
Saya memiliki kerangka data yang diatur seperti berikut: df <- data.frame("id" = c(111,111,111,222,222,222,222,333,333,333,333), "Location" = c("A","B","A","A","C","B","A","B","A","A","A"), "Encounter" = c(1,2,3,1,2,3,4,1,2,3,4)) id Location Encounter 1 111 A 1 2 111 B 2 3 111 A 3 4 222 A 1 5 222 C 2 6 222 B 3 7 222 A 4 …