Collecting the first digit of 1000 random numbers and putting each 9 digits into frequency - excel

I have created 1000 random numbers down a spreadsheet (A1,A1000), But i would like to find the amount of times each first digit comes up.
example
12345
1354
2849
Digit 1 comes up twice,
Digit 2 comes up once
(in spreadsheet terms)

In B1 enter:
=LEFT(A1,1)
and copy down
In C1 enter:
=COUNTIF($B$1:$B$1000,ROW())
and copy down thru C9

Directly without a helping column, in B1:B9
=SUMPRODUCT(--((LEFT($A$1:$A$1000,1)+0)=ROW())*1)

Related

How to add 5 cells consecutively after an interval of 5 cells in a row of 200 cells?

I have a row of 200 cells. I have to add/average first five cells (A:E), and then take a break of 5 cells and then add/average second five cells (K:O) and so on till the end of the row. How can I do this?
I have tried doing it manually. Actually, I can do this manually but wanted to know if I can do this automatically.
I did a test making some faking data like this:
It's just a bunch of numbers from A1 to CB1. 80 numbers in total. 5 first numbers are 1, then next 5 are 2, next 5 numbers are again 1, then next 5 numbers are again 2, and so on.
This mean that there are 80 numbers, where 40 are 1 and 40 are 2. I want to get the average of first five cells (A:E), and then take a break of 5 cells and then average second five cells (K:O) and so on till the end of the row. In other words, I want to get the average of the 40 cells that contains a 1 value, and it should return a 1.
For this, I've used an array formula:
=AVERAGE(IF(VALUE(RIGHT(COLUMN(A1:CB1);1))<6;IF(VALUE(RIGHT(COLUMN(A1:CB1);1))>0;A1:CB1)))
NOTE: Because this is an array formula, it must be inserted pressing ENTER+CTRL+SHIFT instead of
only ENTER, or it won't work!
How this works?
You want to sum/average only values that are in columns where last digit of column number is 1 to 5, this means columns 1,2,3,4,5,11,12,13,14,15,21,22,23,24,25, and so on. So this works this way:
The part that says COLUMN(A1:CB1) will get an array of column numbers.
RIGHT(COLUMN(A1:CB1);1) will get last digit of each column number, but as text
VALUE(RIGHT(COLUMN(A1:CB1);1)) will convert that last digit into a number.
Then with both IFS, we get an array of only those values where last digit of column number is >0 and <6, and we get the average. I get as result of my average 1 and it's true, because the average of 40 times 1 is equal to 1.
Hope this works for you. You can adapt this easily to make it work with 200 cells.
For example:
In A2 put:
=IF(MOD(COLUMN(),10)=1,AVERAGE(INDEX(1:1,,COLUMN()):INDEX(1:1,,COLUMN()+4)),"")
Drag right.
You can use SUMPRODUCT to add the amounts in the columns and divide by 100:
=SUMPRODUCT(--ISEVEN(INT((COLUMN(A1:GR1)-1)/5)),A1:GR1)/100
if you do not always have 200 numbers you can make the 100 more dynamic with another SUMPRODUCT:
=SUMPRODUCT(--ISEVEN(INT((COLUMN(A1:GR1)-1)/5)),A1:GR1)/SUMPRODUCT(ISEVEN(INT((COLUMN(A1:GR1)-1)/5))*(ISNUMBER(A1:GR1)))
this function have CTRL+SHift+Enter and drag this function until your last data IF(OR((RIGHT(COLUMN(A5),1)+0)={1,2,3,4,5}),A5,--FALSE)
You Find The Columns only which end (1,2,3,4,5) , in last. You use Sum function For Add.

Excel countif(s) multiples

I'm trying to calculate the count of multiple occurrences of a figure using countif.
I have the range set but I need a calculation which can count in multiples of 50 without me having to type thousands of versions of countif (=COUNTIF(B2:B5,">=50")-COUNTIF(B2:B5,">100" etc.).
Data Count
50 1
70 1
80 1
10 0
150 3
This data should show 6 but at the moment I'm getting 4.
First you can start by making bins. you can make it with Data analysis tool or half manual
Like in the example, on A2 enter 0 and on b2 enter =a2+50
Same goes for a3 enter =b2 and last on a4 =a3+50
Now you can drag it down as much as you like.
Instaed of using countif use sumif finction. let's assume your data is on cloumn H and the values you want to sum are in column I, then on c2 enter
=SUMIFS(I:I,H:H,">"&A2,H:H,"<="&B2)
you can drag it down as much as you like.
Simply use Excels ROUNDDOWN function:
e.g. for B2: =ROUNDDOWN(A2/50,0)

Formula to count each individual digit in a cell per column in Excel

I have a list of numbers like below. And I need to know how many of each number are in each cell per column.
My List
1
2
3
4
10
11
12
13
14
21
22
23
24
I need to know how many times 1 occurs throughout the whole list, including double digit numbers, and I need to do this for each number 0-9. The reason I don't just count them is because I have a total of 1,400 numbers that I need to break down. I have tried =COUNTIF but unfortunately it sees numbers such as 22 and ONE number, when I need it to tell me that there are 2, 2s. Is there a way? Thanks!
With your data in A2:A15 and the digit to count in B2 you can use following array formula (confirmed with Ctrl+Shift+Enter):
=SUM(LEN(A2:A15)-LEN(SUBSTITUTE(A2:A15,B2,"")))
This would be a way of doing it:-
=SUM(LEN(A$1:A$10)-LEN(SUBSTITUTE(A$1:A$10,"1","")))
and the same for "2", "3" etc. or put digits 0-9 in a range of cells starting at (say) B1 and enter this in C1 and pull down:-
=SUM(LEN(A$1:A$10)-LEN(SUBSTITUTE(A$1:A$10,B1,"")))
Is an array formula and must be entered with CtrlShiftEnter
To count 1's, use something like:
=SUMPRODUCT(LEN(A2:A14)-LEN(SUBSTITUTE(A2:A14,"1","")))
You can count any digit or character or substring this way.
If you're only ever considering up to double-digit numbers, as you appear to suggest:
=SUMPRODUCT(0+(MID(A$1:A$10,{1,2},1)="1"))
Or, more dynamically, with e.g. 1 in B1:
=SUMPRODUCT(0+(MID(A$1:A$10,{1,2},1)=""&B1))
and copied down.
Regards

excel averaging every 10 rows

I have a big data set which has about 9000 rows. I have a few variables for every year from 1960 onwards, and I need to average them in ten year bins. So I have something like:
1
2
3
4
2
3
4
5
Now I need to average the first ten rows, then the next ten, and so on, for all 9000-odd rows. I can do that, but then I get all these rows averaged in the middle which I don't need, and I can't go about deleting those many rows. There has to be an easy way to do this, surely?
Would appreciate any help!
Suppose your data starts from A1. Try this one in B1:
=AVERAGE(INDEX(A:A,1+10*(ROW()-ROW($B$1))):INDEX(A:A,10*(ROW()-ROW($B$1)+1)))
and drag it down.
in B1 it would be =AVERAGE(A1:A10)
in B2 it would be =AVERAGE(A11:A20)
in B3 it would be =AVERAGE(A21:A30)
and so on.
General case
If your data starts from An (where n is 2,3,4,...), use this one:
=AVERAGE(INDEX(A:A,n+10*(ROW()-ROW($B$1))):INDEX(A:A,n-1+10*(ROW()-ROW($B$1)+1))
where you should change n to 2,3,4,...

Taking the average of bottom n percent in Excel

I have a column of data in excel that I need to take the average of the bottom 10% of. My data reads:
1
2
3
4
5
6
7
8
9
10
so the average of the bottom 30% would be - (1+2+3)/3 = 2. Is there a way to automate this in excel where all I have to do is give it what percent I want and it gives me the answer?
A simpler version: no Array Formula or Indirect required
Assuming data in column A, and required percentage in cell B1 (as a decimal)
=AVERAGEIF(A:A,"<="&SMALL(A:A,COUNT(A:A)*B1))
I'm not entirely sure what you're looking for when you say 'where all I have to do is give it what percent I want and it gives me the answer', but you could perhaps try AVERAGEIF:
=AVERAGEIF(A1:A10,"<="&COUNTA(A1:A10)*0.3)
Assuming that the data is in the range A1:A10. You can have a reference for the 0.3 for the percentage.
=AVERAGEIF(A1:A10,"<="&COUNTA(A1:A10)*B1)
If you put the percentage in B1, then the formula will change accordingly.
Assuming your data is in A1:A10, and your desired % is in B1:
=AVERAGE(SMALL(A1:A10,ROW(INDIRECT("1:"&(B1*COUNT(A1:A10))))))
Note! This is an Array Formula! That means that you have to enter into the formula bar at the top (not in the cell), and press ctrl shift enter when you're done.
This will wrap the formula in these { }, so you'll know you did it right. Typing them in does not work, you have to ctrl+alt+enter!
How does it work?
ROW(INDIRECT("1:"&(B1*COUNT(A1:A10))))
The Count checks how many items you have in your list, so it knows how many numbers it will need to average. Let's say B1 is 40%.
40% of 10 items is 4, but 40% of 20 is 8.
Since it's 10 entries long, we'll creating an "array", a series of numbers from 1 to 4 (40%).
*SMALL(A1:A10*
SMALL finds the *n*th smallest number in a range. With our array of 1 to 4, it will find the lowest 4 entries.
AVERAGE(
Then we average the result :)

Resources