Hello!
I need some help from this. Again, after thinking, I came up with a table like this.
Yes/No Genders
___________ __________
Yes female
No male
No they
Yes female
yes male
So I guess the question here would be "Have you ever identified yourself as any of these genders at any given time?"
And given the data I want my output to be like this:
Yes/No Female Male They
___________ _______ _____ _____
Yes 16 13 33
No 20 22 7
So basically the genders theyve identifed as would be turned into their own columns.
I was inspired by these mathworks pages:
So these are my thoughts so far:
  • the Yes/No would be logical since they're esstienally true/false
  • of course split apply would be used here.
  • I was also thinking I could use @sum to find the sum of yes and no of the Genders instead of making my own functions since I am not confident in that yet
So what should be my first steps? Here is an idea I have:
MaleT= nnz(ismember(T2.genders(T2.response == true), 'male'))
FemaleF = nnz(ismember(T2.genders(T2.response == false), 'female'))
% repeat above for each true and false of the genders
Not sure what next steps to take from here...

 Accepted Answer

Adam Danz
Adam Danz on 1 Sep 2020
Edited: Adam Danz on 1 Sep 2020
groupsummary() does that but in a different format.
Demo
T = table(categorical({'Y';'N';'N';'Y';'Y'}),...
categorical({'F';'M';'T';'F';'M'}), 'variablenames', {'YN','Gender'})
% T =
% 5×2 table
% YN Gender
% __ ______
% Y F
% N M
% N T
% Y F
% Y M
GS = groupsummary(T,{'YN','Gender'})
% GS =
% 4×3 table
% YN Gender GroupCount
% __ ______ __________
% N M 1
% N T 1
% Y F 2
% Y M 1
Number of "yes" answers associated with "female":
GS.GroupCount(GS.YN=='Y' & GS.Gender=='F')
% ans =
% 2

1 Comment

Oh, okay this will be useful. Thank you so much :-D

Sign in to comment.

More Answers (0)

Categories

Find more on Aerospace Applications 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!