I want to calculate the rank of a sparse $M\times N$ matrix, $M>N$, and to get a set of rows that are linearly independent that also have the same rank. The non-zero entries of the matrix are not concentrated around the diagonal, but they are scattered.
I could try rref or $QR$ to get them. However, I opted (for some reason) to construct the linearly independent set in the following way. I get one row, append it to the current set of linearly independent rows, and check if the rank increases. If yes, I keep the row and add it to the set, since it belongs to the linearly independent set. If the rank remains the same, discard the row. Then I continue with the next row. So, for example, I start with row $1$, (which is obviously of rank $1$), I append to it row $2$, and I calculate the rank of matrix which consists of rows $1$ and $2$. If the rank remains $1$, I discard row $2$. If the rank has increased to $2$, I keep row $2$. Then I continue with row $3$ until I examine all rows. I end up with a matrix $m\times N$, with $m<M$.
The problem is the following. The $M\times N$ matrix has rank $K$. When I follow the above procedure, the max rank I can reach is $L$, with $L<K$, while I would expect to get $K$ linearly independent rows. Also, in many cases, the transpose of the matrix $m\times N$ constructed with the above procedure has a smaller rank than the matrix $m\times N$.
I suspect some numerical issues are at play, but not quite sure. So, the question is what causes the above irregularities? Thanks for any help/suggestions.