Merging tables with partly the same column names, but sometimes different dimensions

20 次查看(过去 30 天)
Hi,
I have two tables with partly the same variable names. I want to merge these together and put them underneath each other, with all values of each variable under each other and empty cases for variables that are not present in the one table.
How can I do this?
Thank you!

采纳的回答

Bora Eryilmaz
Bora Eryilmaz 2022-12-21
编辑:Bora Eryilmaz 2022-12-21
This seems like a table (outer) join problem. Take a look at: https://www.mathworks.com/help/matlab/ref/table.outerjoin.html
Tleft = table({'a' 'b' 'c'}', [1 2 3]', 'VariableNames', {'Key1' 'Var1'})
Tleft = 3×2 table
Key1 Var1 _____ ____ {'a'} 1 {'b'} 2 {'c'} 3
Tright = table({'a','b','d'}', [4 5 6]', 'VariableNames', {'Key1' 'Var2'})
Tright = 3×2 table
Key1 Var2 _____ ____ {'a'} 4 {'b'} 5 {'d'} 6
T = outerjoin(Tleft, Tright, 'MergeKeys', true)
T = 4×3 table
Key1 Var1 Var2 _____ ____ ____ {'a'} 1 4 {'b'} 2 5 {'c'} 3 NaN {'d'} NaN 6

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by