create ordinal array for multiple groups

조회 수: 9 (최근 30일)
Sophia
Sophia 2014년 1월 8일
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);

답변 (0개)

카테고리

Help CenterFile Exchange에서 Categorical Arrays에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by