grouped difference between two tables

1 回表示 (過去 30 日間)
Gregory McFadden
Gregory McFadden 2017 年 11 月 9 日
回答済み: Gregory McFadden 2017 年 11 月 16 日
Is there a slick way to apply a function (in my case find the difference) between two tables if they have the same variable names in both tables but different numbers of rows. in my case I have one table of average values generated by varfun using a grouping variable and I want to subtract the values in that table from the second table for all other variables when the grouping variable matches between the two tables. I can easily loop through it and get it that way or create index groups by row, but as I have not used tables a whole lot, I am hoping there is a neat/efficient way that I have not thought of.
thanks

採用された回答

Gregory McFadden
Gregory McFadden 2017 年 11 月 16 日
What I ended up doing, as I know the table columns and order for both tables, was to use an outer join and then split the table into two, subtracting one from the other. it worked quite well.

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2017 年 11 月 16 日
With one grouping var, you can get the correspondence between rows using ismember. Given that, you can get the differences using braces on the two tables to pull out the numeric data, something like
t3 = t1{:,j} - t2{i,j}
where i is the output of ismember and j is the vars you want to subtract.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by