I have a spreadsheet with 100 columns and 5000 rows, which I imported into Mathematica as a list named data.
First, I select all rows whose 47th element is 2021:
list1 = Select[data,#[[47]]==2021 &];
Then I get the minimum value of all elements in column 89th in list1:
min=Min@list1[[All,89]];
Finally, I would like to display all rows in my original data whose 47th element is 2021 and 89th element is the above minimum:
Select[data,#[[47]]==2021 && #[[89]]==min &]
I don't really like this approach. My question: Do we have another better way to achieve the same result?
If the data has fewer columns like 3 or 4 then I found a solution using Cases. Can we use Cases in my case?
>=min? – Syed Oct 02 '21 at 09:27Caseswith fewer columns. Why can it not be extended? – Syed Oct 02 '21 at 10:01==sign to extract such elements? I think I will let some experienced contributor edit your post with all the relevant information that is slowly coming together. In your title you use the word "effectively". Effective may mean more lines to impress someone, or a one liner to enter a codegolf competition. It may also mean fast performance or better parallel performance. Since you have used this word, you need to clarify what it exactly means before your question can be answered. – Syed Oct 02 '21 at 10:21My problem with Cases is that we need to declare the pattern first. So with 100 columns, it's not a good way.
– Jogn Bunda Oct 02 '21 at 10:35MinimalBy[#[[89]] &] @ Select[#[[47]] == 2021 &] @ datado what you want? – Carl Woll Oct 02 '21 at 14:33