For example, I have an array:
data = {1, 2, 3, 4, 5, 6, 7, 8, 9}
and a corresponding list of weighting factors
weight = {5, 4, 5, 2, 4, 2, 1, 1, 1}
Evaluating
BinCounts[data, {1, 9, 1}]
gives
{1, 1, 1, 1, 1, 1, 1, 1, 1}
,
but
{5, 4, 5, 2, 4, 2, 1, 1, 1}
is the result wanted. How can I get this?
WeightedData[]
? $\endgroup$BinCounts[ Catenate@MapThread[ConstantArray, {data, weight}], {1, 9, 1}]
$\endgroup$WeightedData
you must useHistogram
orHistogramList
. If the data points are all integers, useMerge[Total]@Thread[data -> weight]
. $\endgroup$