Hello,
I am using this cancer dataset. I have 569 samples( rows) and 30 attributes ( 3:30 columns). The second colunms indicates the type of tumor ( 'M' = malignant, 'B' = benign). I want to order first the M samples , then the B samples. How can I do it on matlab?
I would appreciate your response.
P.S. : It's not a homework or an exam
%% Load data
%filename='wdbc.data';
%url=['https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+(Diagnostic)/' filename];
%file_destination = filename;
%websave(file_destination,url);
%Data = readtable(file_destination, 'FileType','text', 'Delimiter', 'comma');
VarNames = {'ID','B/M','mean radius', 'mean texture', 'mean perimeter', ...
'mean area', 'mean smoothness', 'mean compactness', 'mean concavity', ...
'mean concave points', 'mean symmetry', 'mean fractal dimension', ...
'radius error', 'texture error', 'perimeter error', 'area error', ...
'smoothness error', 'compactness error', 'concavity error', ...
'concave points error', 'symmetry error', ...
'fractal dimension error', 'worst radius', 'worst texture', ...
'worst perimeter', 'worst area', 'worst smoothness', ...
'worst compactness', 'worst concavity', 'worst concave points', ...
'worst symmetry', 'worst fractal dimension'};
Data.Properties.VariableNames = VarNames;
Data_30 = Data(:,3:32); % remove column 1 and 2
Data_ar = table2array(Data_30); % transform from table to array

1 件のコメント

Walter Roberson
Walter Roberson 2023 年 1 月 2 日
[~, idx] = sort(T{:, 2}, 'descend');
newT = T(idx, :) ;
for table T

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2023 年 1 月 2 日

1 投票

One approach is to usee the sortrows function —
Data = table(randi(1E4,6,1),['M';'B';'M';'M';'B';'B'], rand(6,1), randn(6,1), randi(9,6,1))
Data = 6×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ________ _________ ____ 2546 M 0.080991 -1.7018 5 2152 B 0.82521 1.8717 8 8207 M 0.55569 0.074832 7 8258 M 0.65973 -0.021411 3 8687 B 0.95815 0.64405 5 8609 B 0.73313 -1.166 6
Data = sortrows(Data,2, 'descend')
Data = 6×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ________ _________ ____ 2546 M 0.080991 -1.7018 5 8207 M 0.55569 0.074832 7 8258 M 0.65973 -0.021411 3 2152 B 0.82521 1.8717 8 8687 B 0.95815 0.64405 5 8609 B 0.73313 -1.166 6
.

カテゴリ

ヘルプ センター および File ExchangeFractals についてさらに検索

タグ

質問済み:

2023 年 1 月 2 日

回答済み:

2023 年 1 月 2 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by