I'm sorry that I cannot explain exactly. So, I'll ask with simple example.
While I'm looking at This question I use for loop to replace yes value to N/A.
stim <- c("a", "k", "y", "j", "t", "Stop", "f", "l", "b", "a", "c", "Stop")
df <- data.frame(stim)
df<- df%>%
mutate(YesorNo = ifelse(stim == "Stop", "N/A", "yes"))
for (i in 1:dim(df)[1]){
if (df$YesorNo[i] == "N/A") {
if(i == 1){
} else {
df$YesorNo[i-1] = "no"
}
}
}
In for loop above, how can I call that YesorNo[i-1] in dplyr?
Similarly, for a fixed number n, how to call YesorNo[i-n]?