Trying calculate the median of a list, I tried many workflows but I did not succeed. I know there are external plugins for this, but I am very curious, if and how one can define the following condition in GH to calculate the median:
If the length of the list is odd, give the item in centre
else, give the average of the two centred items
I would appreciate your ideas.
Here is a way using a Stream Filter as a kind of switch depending on if the list is odd or even. Median Switch.gh
Thank you very much @Dani_Abalde and @Michael_Pryor for the brilliant solutions.
What I specifically learned from you was the trick to connect 2 indexes to List Item in a way that it can result in one or two items, and the use of Stream Filter, which I was not aware of.
And in case it would be of interest for somebody else in the forum, I updated @Michael solution based on my needs. That is:
- I added sorting in the beginning,
- Replaced Average with Mass Addition and Division, as panels cannot connect to Average directly,
- Simplified the odd/even detection.
It will be much simpler to use script component to calculate.