How order a dataset
이전 댓글 표시
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
2023년 1월 2일
[~, idx] = sort(T{:, 2}, 'descend');
newT = T(idx, :) ;
for table T
답변 (1개)
Data = table(randi(1E4,6,1),['M';'B';'M';'M';'B';'B'], rand(6,1), randn(6,1), randi(9,6,1))
Data = sortrows(Data,2, 'descend')
.
카테고리
도움말 센터 및 File Exchange에서 Fractals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!