Frequency question

H

Harvey Waxman

I recently discovered the very useful frequency function.

Is there a way to get the average of resulting items in the frequency ranges?
Or does one have to sort the data and calculate the average of each range
manually?

Am I confusing you?

--
Harvey Products makers of Dinghy Dogs
The Boater's Best Friend
http://www.dinghydogs.com
Ladies' handbags and accessories
http://www.deducktibles.com
Remove thefrown to email me
 
J

JE McGimpsey

Harvey Waxman said:
I recently discovered the very useful frequency function.

Is there a way to get the average of resulting items in the frequency ranges?

Or does one have to sort the data and calculate the average of each range
manually?

Not using the frequency function, but one way:

Say your values are in A1:A100, your bins in B1:B10, and your
frequencies in C1:C10. Then Average in Bin1:

D1: =SUMIF($A$1:$A$100,"<=10")/C1
D2: =SUMPRODUCT(--($A$1:$A$100>B1),--($A$1:$A$100<=B2),$A$1:$A$100)/C2


Copy D2 down to D10.

Another way (array-entered: CMD-RETURN):

D1: =AVERAGE(IF($A$1:$A$100<=B1,$A$1:$A$100))
D2: =AVERAGE(IF(($A$1:$A$100<=B2)*($A$1:$A$100>B1),$A$1:$A$100))
 
H

Harvey Waxman

JE McGimpsey said:
Not using the frequency function, but one way:

Say your values are in A1:A100, your bins in B1:B10, and your
frequencies in C1:C10. Then Average in Bin1:

D1: =SUMIF($A$1:$A$100,"<=10")/C1
D2: =SUMPRODUCT(--($A$1:$A$100>B1),--($A$1:$A$100<=B2),$A$1:$A$100)/C2


Copy D2 down to D10.

Another way (array-entered: CMD-RETURN):

D1: =AVERAGE(IF($A$1:$A$100<=B1,$A$1:$A$100))
D2: =AVERAGE(IF(($A$1:$A$100<=B2)*($A$1:$A$100>B1),$A$1:$A$100))
Thanks.

What about the last entry in the extra cell, where there is no bin?

But more importantly could you describe in words what's happening?
D1: =SUMIF($A$1:$A$100,"<=10")/C1
I never understood the SUMIF and SUMPRODUCT functions. Whence this: "<=10"?
D2: =SUMPRODUCT(--($A$1:$A$100>B1),--($A$1:$A$100<=B2),$A$1:$A$100)/C2

I'm scratching my head :)
D1: =AVERAGE(IF($A$1:$A$100<=B1,$A$1:$A$100)) Translate please
D2: =AVERAGE(IF(($A$1:$A$100<=B2)*($A$1:$A$100>B1),$A$1:$A$100))
Is there an extra "(" after the IF? And translate also.

They do work but I'd really appreciate understanding better what is happening.

Really appreciate your work.

Harvey





--
Harvey Products makers of Dinghy Dogs
The Boater's Best Friend
http://www.dinghydogs.com
Ladies' handbags and accessories
http://www.deducktibles.com
Remove thefrown to email me
 
J

JE McGimpsey

Harvey Waxman said:
What about the last entry in the extra cell, where there is no bin?
If you choose to have no bin in the last cell (I do, just for
completeness), use (array-entered)

=AVERAGE(IF($A$1:$A$100>90,$A$1:$A$100))

where 90 is the value in your highest bin.
But more importantly could you describe in words what's happening?

Make sure you take a look at Help, but in this case, the SUMIF() looks
at all the values in A1:A100, and if their value is less than or equal
to 10, sums them. That sum is divided by the value returned by Frequency
for your first bin - i.e., the number of cells with values <=10. You
could use

=SUMIF($A$1:$A$00,"<=10",$A$1:$A$100)/C1

to specify that A1:A100 is the range to be added, but the default is to
add the same range as the criterion is evaluated over.
I never understood the SUMIF and SUMPRODUCT functions. Whence this: "<=10"?

In this formula ($A$1:$A$100>B1) generates an array of 100 TRUE/FALSE
values, depending on whether the cells in A1:A100 are greater than B1.
SUMPRODUCT() only works with numeric arrays, so it can't use the boolean
array directly. The double unary minus first coerces each element of
that array to -1/0s, respectively, then to 1/0.

Similarly, the --($A$1:$A$100<=B2) creates a 100 element array of 1/0s.
SUMPRODUCT then multiplies these arrays together to produce a third
array - if both of the elements of the first two arrays are 1, then the
corresponding element of the third array will equal 1 (1*1). A zero in
either element will result in a zero in the third array. That array is
then multiplied by the array $A$1:$A$100 producing a final array that
contains the values in A1:A100 that meet both criteria. That array is
then summed.

You might want to look here for another explanation:

http://www.mcgimpsey.com/excel/variablerate1.html
I'm scratching my head :)

Translate please

By array entering this formula, Each element of $A$1:$A$100 is compared
to B1, returning a boolean TRUE/FALSE. For each element that is TRUE,
the corresponding value in the TRUE branch of the IF() is returned. The
False branch (which I've left out here) by default returns FALSE.
AVERAGE ignores boolean values, so only values which meet the criterion
are averaged.
Is there an extra "(" after the IF? And translate also.

No, the ( is necessary - here you're multiplying 2 arrays:

($A$1:$A$100<=B2) and ($A$1:$A$100>B1)

Since * has a higher priority than <=, the comparisons need to be
enclosed in parens.
 
H

Harvey Waxman

What about the last entry in the extra cell, where there is no bin?
If you choose to have no bin in the last cell (I do, just for
completeness), use (array-entered)[/QUOTE]

The HELp file says to select one row more than the bins, hence no bin in the
last row. This takes care of any item greater than the last bin.

In any case I appreciate the time you took to explain. Now I have to study.

Thanks again

Harvey


--
Harvey Products makers of Dinghy Dogs
The Boater's Best Friend
http://www.dinghydogs.com
Ladies' handbags and accessories
http://www.deducktibles.com
Remove thefrown to email me
 
J

JE McGimpsey

Harvey Waxman said:
The HELp file says to select one row more than the bins, hence no bin in the
last row. This takes care of any item greater than the last bin.

That's true - but if your last bin has the max value in the range,
there's no need to include that last cell in the Frequency array-entered
formula.

For instance, assume values between 1 to 100 in A1:A100, and the values
25,50,75,100 in B1:B4.

If you're unsure of the max value, you can array-enter this into C1:C5 :

=FREQUENCY(A1:A100,B1:B4)

but, if the values are never > 100, C5 will always be 0. In that case, I
just array-enter the formula into C1:C4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

frequency function 2
restrict calculation 1
keyboard shortcuts 2
sheet size 18
Frequency question 13
update 2
sort question 2
Where is my error? 7

Top