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

1 回表示 (過去 30 日間)
Cheerful
Cheerful 2016 年 10 月 12 日
回答済み: Walter Roberson 2016 年 10 月 12 日
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

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 12 日
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 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by