Hi,
I want to assign categories based on the mean variable of multiple groups in the table below. For each unique combination of set and sp, if there is a single combination then category should be 0; if there is more than a single combination then the biggest mean should have a category of 3; the smallest mean should have a category of 1 and any other mean should have a category of 2.
% Original table
set = [1, 1, 1, 1, 2, 3, 3, 3]';
sp = [23, 23, 45, 45, 10, 23, 23, 23]';
mean = [5.1, 10.6, 23.0, 56.1, 7.8, 78.5, 102.2, 234]';
T = table(set, sp, mean)
The desired output is here:
% Final table
set = [1, 1, 1, 1, 2, 3, 3, 3]';
sp = [23, 23, 45, 45, 10, 23, 23, 23]';
mean = [5.1, 10.6, 23.0, 56.1, 7.8, 78.5, 102.2, 234]';
category = [1, 3, 1, 3, 0, 1, 2, 3]';
T = table(set, sp, mean, category)
Any ideas ?
Thank you