Sorting Data into a Table
1 view (last 30 days)
I have a dataset that consists of a single column with x amount of rows (only containing, 1, 2, 3s). I want to take this column and form a table and sort the 1s, 2s, and 3s into different columns. I know I will likely need if statements but not sure where to start. I want to form a table with 3 columns and the 1s sorted into one columns, 2s in another, and so on. Any help would be greatly appreciated!
Thank you in advance!!
dpb on 7 Oct 2022
Edited: dpb on 7 Oct 2022
% make up some data
% the engine (cell array solution)
% padded array solution
N=max(histc(ic,u)); % max number of any value
C=nan(N,numel(u)); % preallocate 2D array prefilled to NaN for missing
% convert to table
You don't give enough information to know what is end result here, but one kinda' presumes there is going to be an analysis of these data by the above variable values. If so, probably the best way to store the data is in a table with the conditions as above as variables -- turning the 1:3 vector into a categorical variable with those names as the categories would likely be a good first step.
Then, analyses could follow with groupsummary or the other tools for handling grouping variables in tables. Look up the background information on processing data in tables; particularly the "split apply" workflow; it'll be eye opening of capabilities.