I have a matrix a n columns and m lines. I'd like to efficiently remove the lines that are not entirely composed of numeric values, lines like this:
{6.22926,6.23254,6.23128,,6.23453,6.22548,6.22938,6.23443,}
In this case the last element is not a numeric value, and such line should be removed.
Also, the matrix is quite big, I have no clue what an efficient method would be.
Answer
The following should work:
lis = {{1, 2, 3, 4, 5, 6}, {1, 9, , 4, 6, 2}, {4, a, 3, 7, 1, 2},
{3.4, 5.2, 6.5, 7.7, 6.1, 2}};
Then:
Cases[lis, {__?NumericQ}]
{{1, 2, 3, 4, 5, 6}, {3.4, 5.2, 6.5, 7.7, 6.1, 2}}
We can also use VectorQ with Select
Select[lis, VectorQ[#, NumericQ] &]
If you have Version 10, the following works:
Select[lis, AllTrue @ NumericQ]
Comments
Post a Comment