cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-11498%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ECount%20Sum%20of%20Repeat%20Occurrences%20By%20Specified%20Variable%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11498%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CP%3EI%20would%20like%20to%20create%20a%20count%20sum%20formula%20which%20sums%20the%20number%20of%20occurrences%20of%20a%20value%20by%20a%20specified%20column%20variable.%3C%2FP%3E%3CP%3EI%20want%20to%20know%20by%20a%20specified%20column%20variable%20value%20(i.e.%20Month)%20how%20many%20times%20did%20the%20same%20value%20appear%20in%20the%20column%20of%20interest.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EExample%3A%26nbsp%3B%20Sum%20Type%20of%20Fruit%20By%20Month%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ENew%20Column%20(%20%22Count_Fruit_Mo%22%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20numeric%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20continuous%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20formula%20or%20command%20TBD%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20)%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CTABLE%20border%3D%221%22%20class%3D%22jiveBorder%22%20style%3D%22border%3A%201px%20solid%20rgb(0%2C%200%2C%200)%3B%20width%3A%20100%25%3B%22%3E%3CTBODY%3E%3CTR%3E%3CTH%20style%3D%22text-align%3A%20center%3B%20background-color%3A%20%236690bc%3B%20color%3A%20%23ffffff%3B%20padding%3A%202px%3B%22%20valign%3D%22middle%22%3EMONTH%3C%2FTH%3E%3CTH%20style%3D%22text-align%3A%20center%3B%20background-color%3A%20%236690bc%3B%20color%3A%20%23ffffff%3B%20padding%3A%202px%3B%22%20valign%3D%22middle%22%3E%3CSTRONG%3EFRUIT%3C%2FSTRONG%3E%3C%2FTH%3E%3C%2FTR%3E%3CTR%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E1%3C%2FTD%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E%3CP%3EORANGE%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E1%3C%2FTD%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E%3CP%3EORANGE%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E1%3C%2FTD%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3EAPPLE%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E2%3C%2FTD%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3EORANGE%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E2%3C%2FTD%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3EAPPLE%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E%3C%2FTD%3E%3CTD%20style%3D%22padding%3A%202px%3B%22%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%3C%2FP%3E%3CP%3E%2F%2F%20a%20Summation%20command%20appears%20to%20function%20for%20the%20entire%20column%2C%20but%20does%20not%20allow%20specification%20by%20another%20column%20variable.%3C%2FP%3E%3CP%3E%2F%2F%20formula(%20Summation(%20i%20%3D%201%2C%20N%20Row()%2C%20%3AFRUIT%3CI%3E%20%3D%3D%20%3AFRUIT))%3C%2FI%3E%3C%2FP%3E%3CP%3E%2F%2F%26nbsp%3B%20ORANGE%20%3D%203%3B%20APPLE%20%3D%202%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EI'm%20hoping%20to%20generate%2C%3C%2FP%3E%3CP%3E%3AMonth%20%3D%201%3B%26nbsp%3B%20%3AFruit%20%3D%20%22ORANGE%22%3B%26nbsp%3B%20%3ACount_Fruit_Mo%20%3D%202%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2013.3333330154419px%3B%22%3E%3AMonth%20%3D%202%3B%26nbsp%3B%20%3AFruit%20%3D%20%22APPLE%22%3B%26nbsp%3B%20%3ACount_Fruit_Mo%20%3D%201%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-324785%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EThanks!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-324785%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EThanks%20MS%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20helped%20me%20count%20up%20duplicate%20columns%20that%20I%20know%20are%20replicate%20measurements.%20It's%20very%20fast%20for%20a%204000%20row%20table%20we%20have.%20Now%20I%20can%20weight%20columns%20appropriately%20by%20the%20amount%20of%20replicate%20measurements%20are%20taken.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11503%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Count%20Sum%20of%20Repeat%20Occurrences%20By%20Specified%20Variable%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11503%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESorry%20-%20I%20removed%20%22dt%20%26lt%3B%26lt%3B%22%20and%20it's%20working.%26nbsp%3B%20The%20post%20has%20been%20corrected%20above.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11502%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Count%20Sum%20of%20Repeat%20Occurrences%20By%20Specified%20Variable%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11502%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EI%20get%20an%20error.%26nbsp%3B%20Here's%20the%20log%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EName%20Unresolved%3A%20f%7B5%7D%20in%20access%20or%20evaluation%20of%20'f'%20%2C%20f%2F*%23%23%23*%2F%0A%0AIn%20the%20following%20script%2C%20error%20marked%20by%20%2F*%23%23%23*%2F%0A%0Adt%20%3D%20New%20Table(%20%22Month-Fruit%22%2C%0A%0AAdd%20Rows(%205%20)%2C%0A%0ANew%20Column(%20%22Month%22%2C%0A%0ANumeric%2C%0A%0AContinuous%2C%0A%0AFormat(%20%22Best%22%2C%2012%20)%2C%0A%0ASet%20Values(%20%5B1%2C%201%2C%201%2C%202%2C%202%5D%20)%0A%0A)%2C%0A%0ANew%20Column(%20%22Fruit%22%2C%0A%0ACharacter%2C%0A%0ANominal%2C%0A%0ASet%20Values(%20%7B%22ORANGE%22%2C%20%22ORANGE%22%2C%20%22APPLE%22%2C%20%22ORANGE%22%2C%20%22APPLE%22%7D%20)%0A%0A)%0A%0A)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20Summarize(%20f%20%3D%20by(%20%3Amonth%2C%20%3AFruit%20)%2C%20c%20%3D%20count%20)%3B%0A%0AShow(%20f%2F*%23%23%23*%2F%2C%20c%20)%3B%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ef%20%3D%20%7B%7B%221%22%2C%20%221%22%2C%20%222%22%2C%20%222%22%7D%2C%20%7B%22APPLE%22%2C%20%22ORANGE%22%2C%20%22APPLE%22%2C%20%22ORANGE%22%7D%7D%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ec%20%3D%20%5B1%2C%202%2C%201%2C%201%5D%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11501%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Count%20Sum%20of%20Repeat%20Occurrences%20By%20Specified%20Variable%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11501%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EThank%20you.%26nbsp%3B%20Very%20helpful.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11500%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Count%20Sum%20of%20Repeat%20Occurrences%20By%20Specified%20Variable%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11500%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EYou%20can%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F15.2%2F%23page%2Fjmp%2Fstore-summary-statistics-in-global-variables.shtml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3ESUMMARIZE%3C%2FA%3E%20command%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20New%20Table(%20%22Month-Fruit%22%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Add%20Rows(%205%20)%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20New%20Column(%20%22Month%22%2C%20Numeric%2C%20Continuous%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Format(%20%22Best%22%2C%2012%20)%2C%20Set%20Values(%20%5B1%2C%201%2C%201%2C%202%2C%202%5D%20)%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20)%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20New%20Column(%20%22Fruit%22%2C%20Character%2C%20Nominal%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20Values(%20%7B%22ORANGE%22%2C%20%22ORANGE%22%2C%20%22APPLE%22%2C%20%22ORANGE%22%2C%20%22APPLE%22%7D%20)%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20)%0A)%3B%0A%0Asummarize(f%20%3D%20by(%3Amonth%2C%20%3AFruit)%2C%20c%20%3D%20count)%3B%0Ashow(f%2C%20c)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20'Courier%20New'%3B%20color%3A%20navy%3B%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3Ef%20%3D%20%7B%7B%221%22%2C%20%221%22%2C%20%222%22%2C%20%222%22%7D%2C%20%7B%22APPLE%22%2C%20%22ORANGE%22%2C%20%22APPLE%22%2C%20%22ORANGE%22%7D%7D%3B%0Ac%20%3D%20%5B1%2C%202%2C%201%2C%201%5D%3B%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20way%20to%20interpret%20the%20output%20is%20that%20there%20are%204%20unique%20combinations%20of%20month%20and%20fruit.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20month%201%2C%20APPLE%20the%20count%20is%201%3CBR%20%2F%3EFor%20month%201%2C%20ORANGE%20the%20count%20is%202%3CBR%20%2F%3EFor%20month%202%2C%20APPLE%20the%20count%20is%201%3CBR%20%2F%3EFor%20month%202%2C%20ORANGE%20the%20count%20is%201%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11499%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Count%20Sum%20of%20Repeat%20Occurrences%20By%20Specified%20Variable%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11499%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EConsider%20using%20the%20function%20%3CEM%3ECol%20Number()%3C%2FEM%3E%20with%20optional%20%3CEM%3EBy-%3C%2FEM%3Earguments%3A%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ECol%20Number(Row()%2C%20%3AMONTH%2C%20%3AFRUIT)%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
aandw
Level II

Count Sum of Repeat Occurrences By Specified Variable?

I would like to create a count sum formula which sums the number of occurrences of a value by a specified column variable.

I want to know by a specified column variable value (i.e. Month) how many times did the same value appear in the column of interest.

Example:  Sum Type of Fruit By Month

New Column ( "Count_Fruit_Mo",

                        numeric,

                         continuous,

                         // formula or command TBD

                          );

MONTHFRUIT
1

ORANGE

1

ORANGE

1APPLE
2ORANGE
2APPLE

// a Summation command appears to function for the entire column, but does not allow specification by another column variable.

// formula( Summation( i = 1, N Row(), :FRUIT == :FRUIT))

//  ORANGE = 3; APPLE = 2

I'm hoping to generate,

:Month = 1;  :Fruit = "ORANGE";  :Count_Fruit_Mo = 2

:Month = 2;  :Fruit = "APPLE";  :Count_Fruit_Mo = 1

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Count Sum of Repeat Occurrences By Specified Variable?

Consider using the function Col Number() with optional By-arguments:

Col Number(Row(), :MONTH, :FRUIT)

View solution in original post

6 REPLIES 6
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Count Sum of Repeat Occurrences By Specified Variable?

Consider using the function Col Number() with optional By-arguments:

Col Number(Row(), :MONTH, :FRUIT)

aandw
Level II

Re: Count Sum of Repeat Occurrences By Specified Variable?

Thank you.  Very helpful.

lloyd_tripp
Level II

Thanks!

Thanks MS,

 

This helped me count up duplicate columns that I know are replicate measurements. It's very fast for a 4000 row table we have. Now I can weight columns appropriately by the amount of replicate measurements are taken.

pmroz
Super User

Re: Count Sum of Repeat Occurrences By Specified Variable?

You can use the SUMMARIZE command:

 

 

dt = New Table( "Month-Fruit",
     Add Rows( 5 ),
     New Column( "Month", Numeric, Continuous,
           Format( "Best", 12 ), Set Values( [1, 1, 1, 2, 2] )
     ),
     New Column( "Fruit", Character, Nominal,
           Set Values( {"ORANGE", "ORANGE", "APPLE", "ORANGE", "APPLE"} )
     )
);

summarize(f = by(:month, :Fruit), c = count);
show(f, c);

 

 

 

f = {{"1", "1", "2", "2"}, {"APPLE", "ORANGE", "APPLE", "ORANGE"}};
c = [1, 2, 1, 1];

 

The way to interpret the output is that there are 4 unique combinations of month and fruit.

 

For month 1, APPLE the count is 1
For month 1, ORANGE the count is 2
For month 2, APPLE the count is 1
For month 2, ORANGE the count is 1

jimloughlin
Level III

Re: Count Sum of Repeat Occurrences By Specified Variable?

I get an error.  Here's the log:

 

 

Name Unresolved: f{5} in access or evaluation of 'f' , f/*###*/

In the following script, error marked by /*###*/

dt = New Table( "Month-Fruit",

Add Rows( 5 ),

New Column( "Month",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Values( [1, 1, 1, 2, 2] )

),

New Column( "Fruit",

Character,

Nominal,

Set Values( {"ORANGE", "ORANGE", "APPLE", "ORANGE", "APPLE"} )

)

);

dt << Summarize( f = by( :month, :Fruit ), c = count );

Show( f/*###*/, c );

 

 

f = {{"1", "1", "2", "2"}, {"APPLE", "ORANGE", "APPLE", "ORANGE"}};

 

c = [1, 2, 1, 1];

 

Jim Loughlin
Loughlin Consulting
pmroz
Super User

Re: Count Sum of Repeat Occurrences By Specified Variable?

Sorry - I removed "dt <<" and it's working.  The post has been corrected above.

Recommended Articles