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 Center および File ExchangeCategorical Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by