I am trying to convert a list of values with frequencies into a single list, so that I can construct boxplots, calculate statistics etc. on the result.
The method I thought of, using a nested list comprehension, failed due to the constraint “List comprehension input list can’t depend on input variable”, so I’m wondering if anyone on this forum has suggestions for how I could accomplish this?
Thanks for this interesting solution. I am really keen for something that occurs instantly so as the frequency list changes it can instantly recalculate the underlying list of points.
The only solution I can think of that does this is assuming that X will only have 9 elements and typing out all 9 cases, then joining them.
I don’t know if @JayChow can provide any insight into the restriction that the calculator has on list comprehensions here?
Yeah, unfortunately for now the list comprehension variables can’t feed into one another — if they could, I believe your approach would have been solid.
This is what I use: Data from Frequency. The idea is to run a cumulative frequency list (line 2) and then map each data-list index i with a datum-index i_d and use that to build up the data-list. The mapping is in line 3, something like “find the minimum index where the cumulative frequency exceeds the data-list index.”
Alternate method! I chatted with Jay off-forum, and he found a way that avoids my messy cumulative frequency index stuff. Here’s the thinking:
Challenge:[L[i] for i=[1...F[i]], i=[1...length(L)]] doesn’t work to repeat data value L[i] exactly F[i] times, because i is seen as a free variable for the comprehension. Solution: Repeat each data value a fixed number of times, then filter down to get the correct number of values!
I created a function that performs the conversion of a frequency table to a data set; perhaps folks will find it useful. The graph has the process broken down into a few sub-functions, but it also includes a single function that combines everything for ease of incorporation into your own project: