I want to filter a data frame (c1p.bim.keep) based on numerical values in one column (V3), so that the values are ascending and where any values that are out of order, the row is removed.
I've tried these commands:
c1p.bim.keep <- c1p.bim.keep %>%
filter(V3>lag(V3))
c1p.bim.keep <- c1p.bim.keep %>%
filter(V3>lag(V3) | V3<lead(V3))
c1p.bim.keep <- c1p.bim.keep %>%
mutate(prev=lag(V3)) %>%
filter(V3>prev | V3<lead(prev))
The problem I'm facing is that I have multiple rows together that need removing, but these commands don't seem to update as one row is removed. I've tried putting in a loop, but this causes so many of the first values to be removed too.
So how can I ensure that all unordered rows are removed without losing so many of the first rows?