Reputation: 73
I have a table and I wish to group the data from the table based on the values of a categorical variable. For example, let's say I have the following columns in a table called "data":
I would like to create two tables with the ages of the people based on their Gender. So one table for the ages of people with Gender == 0 and another for the ages of people with Gender == 1. I want all the rows from the table which meet the conditions, not a summary of the data.
I have tried doing the following but it will only return empty tables:
data_m = groupfilter(data,"Gender",@(x) (x) == 0)
data_f = groupfilter(data,"Gender",@(x) (x) == 1)
Any help would be greatly appreciated, thanks in advance!
Upvotes: 0
Views: 410
Reputation: 36
I don't know about the groupfilter function but you can not use something as:
name = ["Maria" "Jose" "Arnaldo" "Eva" "Schawarza" "Rose"]';´
gender = [0 1 1 0 0 0]';
T = table(name,gender)
male = T(T.gender==1,:)
female = T(T.gender==0,:)
Upvotes: 2