# I need to separate same first column data values and its corresponding second column value.

1 view (last 30 days)
zhoug zho on 18 May 2021
Edited: Adam Danz on 18 May 2021
I have two dimensional data, as shown in figure.
I need to separate same first coloumn (column 1) data values and its corresponding second column (column 2) value, into groups.
How can I do this ?
##### 2 CommentsShow 1 older commentHide 1 older comment
zhoug zho on 18 May 2021
I still need two columns, basically I need to separate all the first column elements that are similar.
And then, as elements of first column are exactly same, so I will consider it one value, but their corresponding values in column 2 will be added and average out of all these similar ,
So in this case, I have one values from column 1 and its corresponding column 2 averaged value.

Adam Danz on 18 May 2021
Edited: Adam Danz on 18 May 2021
Another method using groupsummary
% Create demo table
g = repelem((1:2:9)',randi(4,5,1)+1,1);
T = table(g, rand(numel(g),1).*randi([2,8],numel(g),1), ...
'VariableNames', {'column1','column2'})
T = 16×2 table
column1 column2 _______ ________ 1 5.7244 1 1.6392 1 1.7206 1 0.64037 3 0.073685 3 1.9413 3 1.6698 5 1.3814 5 1.4611 7 1.0805 7 1.1879 7 0.42207 7 1.3179 9 4.5171 9 0.38479 9 2.9267
% Average column 2 for each group in column 1
Tstats = groupsummary(T,'column1','mean','column2')
Tstats = 5×3 table
column1 GroupCount mean_column2 _______ __________ ____________ 1 4 2.4311 3 3 1.2283 5 2 1.4212 7 4 1.0021 9 3 2.6095