I have a long list consists of float numbers with some of them duplicated as shown below.
I want to divide this list into bins;
- with equal bin width so that in each bin there might be one or more than one member, even duplicated numbers come from the main list.
- with variable bin width so that in each bin there will be the same amount of members.
For the first item, I start with deciding on a binning amount and find suitable bin width (in this case 0.001) for this binning amount as below;
binningamount = 996;
min = Floor[Min[DeleteCases[Sort[DeleteDuplicates[list]], "NA"]], 0.1]
max = Ceiling[Max[DeleteCases[Sort[DeleteDuplicates[list]], "NA"]]]
Length[DeleteCases[BinLists[list, {min, max, 0.001}], {}]] == binningamount
and create binned list as below;
binning =
Table[Catch[
Do[If[IntervalMemberQ[Interval[i], list[[j]]] == True, Throw[i]],
{i, Partition[Range[min, max, 0.001], 2, 1]}]], {j, Length[list]}];
I am wondering,
- Is there a way to perform the first item easier than I showed above? For instance, giving the binning amount and get suitable bin width value to apply to list.
- How is it possible to achieve the second item?
Partition
. $\endgroup$ – b.gates.you.know.what Nov 5 '20 at 16:197
then you can not divide it to, say,3
bins of equal length because3
does not divide7
. $\endgroup$ – azerbajdzan Nov 6 '20 at 17:09FindClusters
- that is perhaps what you need instead ofBinLists
. $\endgroup$ – azerbajdzan Nov 6 '20 at 17:17