combining two excel files. second excel file sub group of the first file.

1 回表示 (過去 30 日間)
ALDO
ALDO 2019 年 9 月 27 日
コメント済み: ALDO 2019 年 9 月 30 日
Hi. I have an excel file with 2000 rows and another excel file with 400 rows. I want to add the the second file to the first one at the row that have the matching names. please find example below. I would greatly appriciate the help.Thank you in advance!
tabel 1:
name category1 category 2 ....
112 yes no
888 no yes
986 yes yes
664 no no
table 2:
name result1 result2 .....
743 yes no
112 yes yes
664 no yes
note: the two tables have row name '112' and '664' in common. I want to add data to those row names! and leave the rows that dont match blank.
desired resulting tabel:
name category1 category 2.... result1 result2 ....
112 yes no yes yes
888 no yes
986 yes yes
664 no no no yes

採用された回答

Jyotsna Talluri
Jyotsna Talluri 2019 年 9 月 30 日
編集済み: Jyotsna Talluri 2019 年 9 月 30 日
There can be many ways to do this.One possible way is ..
First join the two tables using 'outerjoin'
t=outerjoin(table1,table2,'Type','left','MergeKeys',true,'LeftKeys',{'name'},'RightKeys',{'name'});
It generates a new table with the columns of table2 appended to the colums of table1 with some NaN values for rows that don't match in the two tables. These NaN values can be replaced by empty values as below
v=t.Properties.VariableNames;
t=table2cell(t);
for i=2:size(t,2)
for j=1:size(t,1)
if isnan(t{j,i})
t{j,i}={[]};
end
end
end
t=cell2table(t,'VariableNames',v);
  1 件のコメント
ALDO
ALDO 2019 年 9 月 30 日
Thank you very much for your fast responce! I will try it out and let you know how it goes

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by