How to merge two columns of a table into a single column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Cheerful
am 12 Okt. 2016
Beantwortet: Walter Roberson
am 12 Okt. 2016
Dear Experts,
I have a table, tableA of 3 columns. There are empty values in the first 2 columns and I want to merge the first 2 columns into a new columns such that there are no empty values.The table is shown below
Asset1 Asset2 Score
Appl Appl 10
IBM " 2
" Google 5
Dell Dell 4
Desired output
Asset Score
Appl 10
IBM 2
Google 5
Dell 4
I think "join" or "outerjoin" wont be able to do it.
Thanks
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Okt. 2016
Letting T be the table:
v = cellfun(@isempty, T.Asset1)+1;
r = [T.Asset1, T.Asset2];
good_asset = r(sub2ind(size(r), (1:size(r,1)).', v));
result = table(good_asset, T.Score, 'VariableNames', {'Asset', 'Score'});
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!