I'm a new user of Mathematica and now I am confused by a problem.
Now I have about 2 million rows of data and 3 columns, i.e. a 2million*3 table. What I am trying to do is select rows of data satisfying two 'AND' conditions, the first column should equal to 18 to 60 AND the second column equal to 1 to 5(both conditions with step 1). Then I have the data in the 3rd column with the same 1st and 2nd column value. The next step I will calculate the Mean or Median or apply distribution analysis base on the Selected results. For example, I need select rows with conditions of Cloume1=18 AND Column2=1.
I wrote
Do[Select[mytable, If[#[[1]] == i&&#[[2]] == j, True, False] &], {i, 18, 60, 1},{j,1,5,1}]
and nothing(NULL) is shown in the output.
I put some sample data as shown below.
{{18, 1, 3.195}, {18, 1, 3.902}, {60, 1, 5.4333}, {60, 1, 3.1}, {60,1, 6.8594}, {60, 1, 3.666}, {60, 1, 3.902}, {60, 1, 1.2666}, {60, 1,3.902}, {60, 1, 2.3}, {60, 1, 4.3}, {60, 1, 3.902}, {60, 1,3.902}, {60, 1, 3.563}, {60, 1, 3.902}, {60, 1, 51.835}, {60, 1,3.902}}
How can I fix it? Thank you for your help!
Do
does not return anthing, you need to useTable
3) but this approach is not ok anyway you can start with:Select[mytable, (#[[1]] == 18 || #[[1]] == 60) && (#[[2]] == 1 || #[[2]] == 5)&]
, orCases[mytable, { 18|60, 1|5, ___}]
$\endgroup$mytable
is very large, the code will be very slow, as theDo
loop will makeSelect
go thourhg the data $60\times 5$ times. You should avoid procedurical loops. Maybe something likeTally
is already does the sorting you need. $\endgroup$Median[Select[data, #[[1 ;; 2]] == {18, 2} &][[All, 3]]]
, and repeat this command from 18 to 60.(it took me some time). $\endgroup$