let's say I have a 10x3 matrix m where I want to check for all zeros and two consecutive zeros in the first column. I want to remove all rows containing a zero in the first column and also all other rows after two consecutive zeros in the first column starting from a certain point in the matrix and either removing values before or after two zeros in a row.
col1 col2 col3
[1,] 2 2 2
[2,] 2 2 2
[3,] 2 2 2
[4,] 2 2 2
[5,] 2 0 2
[6,] 2 2 2
[7,] 2 0 2
[8,] 2 0 2
[9,] 2 2 2
[10,] 2 2 2
dput= structure(c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 0,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), .Dim = c(10L, 3L), .Dimnames = list(
NULL, c("col1", "col2", "col3")))
expected result= col1 col2 col3
[1,] 2 2 2
[2,] 2 2 2
Removing rows 1,2,3,4,5,6,7, and 8.
dput
to export your data – HubertL