How to merge two columns of a table into a single column

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
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'});

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by