Subscribe Bookmark RSS Feed

counting rows based on values in another column

dwaterson

Community Trekker

Joined:

Jul 25, 2014

I have a column that defines a grouping, like a column called 'gender' that contains the values 'male' and 'female'. I want to know how many rows in the dataset = 'male' and how many rows in the dataset = 'female'.

2 ACCEPTED SOLUTIONS

Accepted Solutions
vince_faller

Super User

Joined:

Mar 17, 2015

Solution

dt = current data table();

dt << Select Where(:Gender == "male");

male = nrows(dt << Get Selected rows());

dt << Select Where(:Gender == "female");

female = nrows(dt << Get Selected rows());

pmroz

Super User

Joined:

Jun 23, 2011

Solution

You can use Tables > Summary.  Here's a JSL version:

dt = open("$sample_data/Big Class.jmp");

dt << Summary( Group( :sex ), N );

There's also the SUMMARIZE command in JSL.  You need a numeric column to get this to work though:

summarize(gsex = by(:sex), gcount = count(:height));

print(gcount);

[18, 22]

5 REPLIES
vince_faller

Super User

Joined:

Mar 17, 2015

Solution

dt = current data table();

dt << Select Where(:Gender == "male");

male = nrows(dt << Get Selected rows());

dt << Select Where(:Gender == "female");

female = nrows(dt << Get Selected rows());

pmroz

Super User

Joined:

Jun 23, 2011

Solution

You can use Tables > Summary.  Here's a JSL version:

dt = open("$sample_data/Big Class.jmp");

dt << Summary( Group( :sex ), N );

There's also the SUMMARIZE command in JSL.  You need a numeric column to get this to work though:

summarize(gsex = by(:sex), gcount = count(:height));

print(gcount);

[18, 22]

dwaterson

Community Trekker

Joined:

Jul 25, 2014

Thank you for these responses. Is there any way to do this within a column formula?

ms

Super User

Joined:

Jun 23, 2011

Col Number(Row(), :Gender)

jason_paquette

Community Trekker

Joined:

Jan 26, 2015

Thanks! This helped me out.