I need help filtering the following data frame (this is a simple example):
mx = as.data.frame(cbind(c("-", "-", "-", "-", "mutation", "+", "+", "+", "+") , c(F, T, F, F, F, F, T, F,T)) ) colnames(mx) = c("mutation", "distance") mx mutation distance 1 - FALSE 2 - TRUE 3 - FALSE 4 - FALSE 5 mutation FALSE 6 + FALSE 7 + TRUE 8 + FALSE 9 + TRUE
I need to filter based on the second column (distance) so that it looks like this:
mutation distance 3 - FALSE 4 - FALSE 5 mutation FALSE 6 + FALSE
I need to delete all the lines until the last TRUE that is before the line with the value mx$mutation = mutation (so that lines 1 and 2), and all the lines after the first TRUE that occur after mx$mutation = mutation (therefore line 7 onwards )
source share