I am generating a large dataset and would like to manipulate it afterwards. Here is an example matrix of my dataset. The first 3 columns are data and the last two columns are indices of the runs (each row contains the results of a single run).
mat = {{0.2, 0.1, 0.01, 1, 1}, {0.1, -0.5, 0.4, 1,
2}, {0.4, -1.1, -0.1, 2, 1}, {0.7, 1., 1., 2, 2}, {0.3, 0.5, 0.6,
3, 1}, {0.9, 1.1, 0.6, 3, 2}};
%//MatrixForm
I would like to:
a. extract row 3,4, and 5, based on the criteria that any element in the columns 1-3 is either < -1 or >1, or
b. extract rows based on the indices, e.g. row with 1,2 and row with 3,1 in the last two columns.
In either case, the result would be two new matrices, one with the remaining rows (not extracted) and another with the extracted rows.
The best I've been able to do is extract rows based on any element using Select[]
and MemberQ[]
which is not precise enough e.g. Select[mat, MemberQ[#, 3] &]
Many thanks.
GroupBy
to split the matrix into two parts. $\endgroup$