I want to take the average of rows which would result in a column (array). Example input:
3 4
4 4
4 6
With an array formula I want to create:
3.5
4
5
The average is the sum of numbers divided by the count of that numbers.
So first add them (A1:A3+B1:B3)
3+4 = 7
4+4 = 8
4+6 = 10
Then divide by the number of numbers(/2):
7/2 = 3.5
8/2 = 4
10/2 = 5
{=(A1:A3+B1:B3)/2}
edit after comment from op:
formula for addition without adding column manually from https://productforums.google.com/forum/#!topic/docs/Q9x44sclzfY
{=mmult(A1:B3,sign(transpose(column(A1:B3))))/Columns(A1:B3)}
This is one way to do that in Excel
=SUBTOTAL(1,OFFSET(A1:B3,ROW(A1:B3)-MIN(ROW(A1:B3)),0,1))
OFFSET
supplies an "array of ranges", each range being a single row, and SUBTOTAL
with 1 as first argument, averages each of those ranges. You can use this in another formula or function or entered in a range on the worksheet.
The advantage over Siphor's suggestion with MMULT
is that this will still work even with blanks or text values in the range (those will be ignored)
Excel for 365 and Excel Online have the BYROW
and BYCOL
functions now. To perform the same function as above, just use the following formula:
=BYROW(A1:B3, LAMBDA(row, AVERAGE(row)))
BYROW function - Microsoft Support
To put it simply, the BYROW
and BYCOL
functions apply the supplied LAMBDA
function to each row in the array. In this case, the provided LAMBDA
function applies the AVERAGE
function to each of its inputs. Since BYROW
supplies each row of the array, AVERAGE
is applied to each row.
If first column is A and the second is B, then enter this formuls in column C:
=AVERAGE(A1,B1)
and extend it to the last row
Also you can use a range if you have more than 2 columns (this function allows for some cells to be empty):
=AVERAGE(A1:F1)