How can i create a new table by combining the rows with identical names but with fifferent data under the same variables?
2 views (last 30 days)
Show older comments
I have two large tables and they have the same column 1 and variables. The only thing different is the data. Now what i want to be able to do is to combine identical rows make a new chart were they all appear grouped. I want to then do a t test.
Answers (1)
Arjun
on 1 Oct 2024
I see that you want to combine two tables based on common column. To do this, you can use the “innerjoin” function of MATLAB to merge the tables based on a single column.
Once the merged table is ready, we can use the “ttest” function to do a t test on the combined table.
You can refer to the code below for better understanding:
% Create sample tables
table1 = table(['A'; 'B'; 'C'], rand(3, 1), rand(3, 1), 'VariableNames', {'ID', 'Var1', 'Var2'});
table2 = table(['A'; 'B'; 'C'], rand(3, 1), rand(3, 1), 'VariableNames', {'ID', 'Var1', 'Var2'});
% Perform inner join on the 'ID' column
combinedTable = innerjoin(table1, table2, 'Keys', 'ID', 'RightVariables', {'Var1', 'Var2'});
% Perform t-test on the corresponding columns
[h, p] = ttest(combinedTable.Var1_table1, combinedTable.Var1_table2);
% Display the results
disp(['Hypothesis test result: ', num2str(h)]);
disp(['p-value: ', num2str(p)]);
You can go through the documentation of the following functions for better understanding:
- innerjoin: https://www.mathworks.com/help/matlab/ref/table.innerjoin.html
- ttest: https://www.mathworks.com/help/stats/ttest.html[SS1]
I hope this explanation works!
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!