Table row retrieval with dependent on column values
Show older comments
I am dealing with a sorting issue on a table which. The table looks like follows:
Rec_id =[1; 1; 2; 2; 2; 3; 3; 4; 4]; % for clarification: the values here go up to 80 in the original table
Rec_type= {'A';'B';'A';'B';'C';'A';'C';'A';'B'};
data_table = table(Rec_id, Rec_type)
From this I'm trying to extract all rows of Rec_id's which have Rec_type='B', but also the rows of the same Rec_id with Rec_type='A'.
The table i try to extract from the former should look like this:
Rec_id =[1; 1; 2; 2; 4; 4]; % Rec_id = 3 gets filtered out completely, since there is no Rec_id = 3 with Rec_type 'B'
Rec_type= {'A';'B';'A';'B';'A';'B'};
new_table = table(Rec_id, Rec_type)
My approach was to find all Rec_id's that have a Rec_type of 'B' and use these.
Ids_corr_to_type_B = table.Rec_id(table.Rec_type == 'B');
But I was unable to use the array retrieved from that operation successfully.
Thank you for your help!
Accepted Answer
More Answers (0)
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!