Average length of a string

ss55

New Member
Joined
Jun 10, 2005
Messages
34
Hi,

I have a row of 1's and blanks, where there might be 10 consecutive 1's, followed by four consecutive blanks. I want to calculate the average length of a string of 1's in the row -- does anyone have any ideas as to how this might be accomplished?

Thanks.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
=AVERAGE(IF(FREQUENCY(IF(A1:A30=1, ROW(A1:A30)), IF(A1:A30<>1, ROW(A1:A30)))>0, FREQUENCY(IF(A1:A30=1, ROW(A1:A30)), IF(A1:A30<>1, ROW(A1:A30)))))

The formula MUST be confirmed with Ctrl+Shift+Enter rather than just Enter.
 
Upvote 0
this formula seems to give me the a value that is very close to =COUNTIF(A1:A30, 1)

maybe there is a typo in the formula?
 
Upvote 0
Post an example that's wrong.
 
Upvote 0
so, let's say beginning in C5 and ending in X5, we have the following:
1111111 111 1 111

there are 14 total 1's
the average length of a string is 3.5 -- (7+3+1+3)/4

your formula produces the number 14 when applied to this row
 
Upvote 0
If the data is disposed in a row instead of a column, change ROW(...) to COLUMN(...)
 
Last edited:
Upvote 0
=AVERAGE(IF(FREQUENCY(IF(A1:A30=1, ROW(A1:A30)), IF(A1:A30<>1, ROW(A1:A30)))>0, FREQUENCY(IF(A1:A30=1, ROW(A1:A30)), IF(A1:A30<>1, ROW(A1:A30)))))

The formula MUST be confirmed with Ctrl+Shift+Enter rather than just Enter.

I've just spent the better part of the day trying to figure this out, but I think I just need to ask.

Is there a way to modify that formula to count the number of times the sequence of 1s exceeds a certain threshold? Say I want to know the number of times it exceeds 10--is that possible?
 
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top