I have data from an IM chat, where each row is a keystroke. I would like to automatically add the column most_recent_enter
(manually added here, for an explanation), where it tracks the most recent row where the keystroke
== ENTER
.
In this example, there are overlapping messages, so the last user to hit ENTER
was not necessarily the most recent user. I am including other columns here, to show what information I have available.
x <- data.frame(overall_idx = 1:14,
sender=c("a","a","a","b","b","b","a",
"a","a","a","b","b","a","a"),
keystroke=c("H","I","ENTER","K","I","ENTER",
"W","H","I","C","W","H","H","T"),
ks_idx=c(0,1,2,0,1,2,0,1,2,3,0,1,3,3),
most_recent_enter=c(NA,NA,NA,"a","a","a","b","b",
"b","b","b","b","b","b")
)
Is there a way to find the most recent row that meets a condition?