AGB 260: Agribusiness Information Technology Arrays and Array Formulas Useful Chapters in the Textbook Regarding this Lecture Chapter 17 Chapter 18 Arrays An array is a collection of items which can easily be represented as cells in Excel spreadsheet. Arrays in Excel can be one or two dimensional which correspond to the rows and columns of the worksheet. A one dimensional array can either be one column or one row. Arrays Cont. A two dimensional array must have both rows and columns. An example of a one dimensional row array: {1,2,3,4,5} Put this in a cell with an equal sign at the beginning, highlight 5 cells in a single row, press F2 and then CTRL-Shift-Enter Arrays Cont. An example of a one dimensional column array: {1;2;3;4;5} An example of a 3x2 two dimensional array: {1,2;3,4;5,6} Single-Cell Array Formulas Single-cell array formulas These formulas give a result in one cell, e.g., ={Sum(A1:A4*B1:B4)}. When entering an array formula, you must activate the cell and press Ctrl+Shift+Enter Single-Cell Array Formulas Cont. Suppose you have the names Bob, Sean, and Stuart in cells A1:A3 If we want to calculate the average length of individuals’ names, we can do it in a single formula using the idea of an array =AVERAGE(LEN(A1:A3)) Multi-Cell Array Formulas Multi-cell array formulas These formulas give a result that spans multiple cells. In these formulas, you need to select the cells for where the results will be and press F2 to select the cells. Transposing an Array A useful array formula is the Transpose function. This function will take a column array and make it a row array, a row array into a column array, and it will transpose a matrix array. Frequency Function The frequency() function calculates the number of times a value occurs in an array, i.e., it helps you create a histogram. It has two main arguments: The data_array argument is the array of values your interested in The Bins_array is the array that has the numbers to be tallied. Linest Function The Linest() function returns the results of doing a linear regression on a column array of known Y’s regressed against an array of known X’s. Linear regression is based on the concept Y = mx + b Linest Function Cont. There are four arguments to the function: Known_y’s – this is the set of numbers for the dependent variable Known_x’s – this is the set of numbers for the independent variable(s) Const – If you set this to True, it will estimate a nonzero intercept b; false implies set b to zero Stats – True gives you a set of regression statistics, while false returns no statistics Matrix Functions Excel has three useful matrix functions: Mmult() which does matrix multiplication of two arrays Mdeterm() which gives you the determinant of a square matrix Minverse() which gives the inverse of a square matrix Matrix Functions Cont. The functions can be useful when doing matrix algebra, i.e., solving a set of linear equations, but they can have rounding issues For example: x+y= 80 x-y=20