R: Storing different sized matrices in the same array - arrays

I'm sifting through a data set, and grouping certain rows together. The data set is 18 rows by 8 columns. It contains both numerical and word info. My method is as follows: If the first 5 columns of a row are the same as another row, I want group those two rows together in a matrix.
Here is my my issue:
I do not know how many rows will be the same (therefore, when I create a matrix of the rows I won't know its dimensions). I have concluded that I need an array that can store different sized matrices. Is this possible? If not, how would you recommend I store the rows?
Thanks!

Related

SSRS - Print order issue

I have the following scenario: I have a matrix table with dynamic rows and columns, the rows have three groups Product_Type, Manufacturer and Supplier the Columns are stores that are dynamically generated. All the data comes from a single DataSet returned from a stored procedure in SQL Server.
The rows are to big too fit on a single screen and the columns as well, now when this happens the print order must be as follow: if the columns overflows then the columns must print on the following page continuing with all of the rows (the 3 types). If the rows overflows but not the columns then that columns must display on the following page for the remaining rows. These two scenarios is quite straight forward and I already got it to work. If both the columns both overflows it must print as the following picture:
I am struggling to get it right, I am not a novice in SSRS and only know the fundamentals. I have struggled quite a while trying to figure it out and can't seem to get it right.
Any expert advice will be much appreciated.
One way to achieve this if you have two matrixes one after the other.
The first you hide any columns # > x (where x is the number of columns you can fit onto a page) and subsequent matrix hide the column # <= x
Matrix 1
Matrix 2

Get Row and Column Totals from 2d Array in Excel

I wanted to know how to get row and column totals from a 2D array in Excel. This is a fairly common thing to do but I couldn't find an answer to it by searching on row and column totals so I thought it would be worth posting it as a question.
Supposing I wanted to find the lowest column total and highest row total in the following array which is in cells A1:D3:-
1 2 3 4
5 6 7 8
9 10 11 12
my initial thoughts were along the lines of
=min(A1:D3*(column(A1:D3)={1,2,3,4}))
but this kind of simple approach doesn't work. I remembered reading that you had to use mmult in some of these situations and have seen advanced formulae using them but couldn't quite remember how. I shall try and answer my own question but other suggestions are more than welcome.
You can do it with MMULT as you mentioned. The following should work with your setup:
Smallest column
=MIN(MMULT({1,1,1},A1:D3))
Largest row:
=MAX(MMULT(A1:D3,{1;1;1;1}))
Note how many 1s in the array - for the rows calc you need a 1 for each column (i.e. 3) and vica versa for columns. Also note the order of the arrays - it won't work the other way around
Yes you have to mmult to deliver either a column array or row array containing the required totals, then use can use MAX, MIN or any other aggregate function to get the value you require.
Column totals
=MIN(MMULT(TRANSPOSE(ROW(A1:D3))^0,A1:D3))
Row Totals
=MAX(MMULT(A1:D3,TRANSPOSE(COLUMN(A1:D3))^0))
So the idea is that you create a single-row array {1,1,1} and multiply it by the 2D array to end up with an array {15,18,21,24} and take the minimum value from it.
Or create a single-column array {1;1;1;1} and multiply the original array by it to end up with an array {10;26;42} from which you get the maximum value.
Remember that mmult works like the matrix multiplication you might have learned at college where for each cell it works across the cells in the corresponding row of the first array and down the cells of the corresponding column in the second array multiplying each pair and adding them to the total. So the number of columns in the first array must always equal the number of rows in the second array.
These are, as #Scott Craner reminds me, array formulae that have to be entered with
Ctrl Shift Enter

join columns of arrays in matlab

I have the following inputs
dataset 1 with tens of thousands of rows and 5 array columns
dataset 2 with tens of thousands of rows and 3 array columns
I want to join/merge (add) the 3th column of dataset 1 to a new 4th array column of dataset 2 for the elements for which the ID is the same (same value in column 1 of dataset 1 and column 1 of dataset 2). Mathematically you can write it like this I think:
dataset2(i,4)=dataset1(find(dataset1(:,1)==c(i,1)),3);
but how to put it in MATLAB?
None of the methods mentioned in the MATLAB help function or elsewhere on the internet seem to work. I have already tried merge, join, ismember, vectors, but I can't solve the problem.
Does someone have any ideas? I know the problem can be solved with for loops, but i'm not allowed to use them, so I am searching for alternatives.
I believe this is what you want
%We keep the index of all the matching rows
%NOTICE: I changed c(i,1) to dataset2(:,1)
%matches_in_col_1 = find(dataset1(:,1)==dataset2(:,1));
%EDIT: HOW TO COMPARE MORE THAN 2 COLUMNS
%if you want to find matches in 4 datasets just use this
matches_in_col_1 = find(dataset1(:,1)==dataset2(:,1)==dataset3(:,1)==dataset4(:,1));
%now copy the values from those rows into the corresponding row
%of datsaset2
dataset2(matches_in_col_1,4) = dataset1(matches_in_col_1,3);
I'm not 100% sure. Why is i present? were you trying a loop implementation? My solution also assumes that c was supposed to be dataset2

Array multiplication in Excel

In my excel document I have two sheets. The first is a data set and the second is a matrix of the relationship between two of the variables in my data set. Each possibility of the variable is a column in my matrix. I'm trying to get the sum of the products of the elements in two different arrays. Right now I'm using the formula {=SUM(N3:N20 * F3:F20)} and manually changing the columns each time. But my data set is over 800 items...
Ideally I'd like to know how to write a program that reads the value of the variable in my dataset looks up the correct columns in the matrix, multiplies them together, sums the products, and puts the result in the correct place in my data set. However, just knowing the result for all the possible combinations of columns would also save me alot of time. Its an 18x18 matrix. Thanks for any feedback!
Your question is a little bit ambiguous but as far as i understand your question you want to multiply different sets of two columns in the same sheet and put their result into the next sheet, is it so? if so, please post images of your work (all sheets). Your answer is possible even in Excel only without any vba code, thanks.
you can also use =SUMPRODUCT(N3:N20,F3:F20) for your formula instead of {=SUM(N3:N20 * F3:F20)}

Extracting parts of a matrix based on the properties of the elements in the first column

I have some data consisting of 2 columns and thousands of rows. The first column is time data. How do I extract the part of the data where the values in the first column are between say, 100 and 300. I can do that for a single vector x=t(find(t>=100&t<=300)), but I also want the corresponding values from the second column.
This is in Matlab, by the way.
I hope that's clear. Any ideas?
BvV
Use this
x=t(t(:,1)>=100&t(:,1)<=300,:);

Resources