create ordinal array for multiple groups

9 views (last 30 days)
Sophia
Sophia on 8 Jan 2014
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:
  1. Is there another way to join the subsets so that I don't get duplicate _Right and _Left variables (last line of code)?
  2. 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);

Answers (0)

Categories

Find more on Categorical Arrays in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!