create ordinal array for multiple groups
9 views (last 30 days)
Show older comments
I need to categorize a dataset according to different groups. For the example below, I want to create an ordinal array that differs by gender. I first subset the data by gender and then use the ordinal function. My questions are:
- Is there another way to join the subsets so that I don't get duplicate _Right and _Left variables (last line of code)?
- Is there an easier way to do this without having to create subsets of the dataset?
I am using Matlab R2012b version.
load hospital;
subset_m=hospital(hospital.Sex=='Male',:);
subset_f=hospital(hospital.Sex=='Female',:);
edges_f=[0 20 max(subset_f.Age)];
edges_m=[0 30 max(subset_m.Age)];
labels_m = {'0-19','20+'};
labels_f = {'0-29','30+'};
subset_m.AgeGroup= ordinal(subset_m.Age,labels_m,[],edges_m);
subset_f.AgeGroup = ordinal(subset_f.Age,labels_f,[],edges_f);
joinFull=join(subset_f,subset_m,'LeftKeys','LastName','RightKeys','LastName','type','rightouter','mergekeys',true);
0 Comments
Answers (0)
See Also
Categories
Find more on Categorical Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!