Interesting question - sill waiting for an answer?
There is a set of posts with similar questions how to restrict the Col ... aggregation functions to a specific subset.
(mainly: restrict them to the subset of non-excluded rows)
Compute Column Mean while restricting observations used
JMP10: Col Max() and Col Min() functions returned the data from excluded row
Col Functions and Row States
The idea:
If one is interested in the mean height, one can aggregate over all rows - or one can aggreate male and female entries separately.
For the second one the solution is almost as easy as for the first one: just use an additional GroupBy variable to split between wanted and unwanted data.
But, what a user often needs in addition: the values should show up in all respective rows (i.e. also for female).
[The example with the benchmark column in the original post illustrates why such a behavior could make sense.]
With the GroupBy, it's easy to get the correct values - but how to distribute them over ALL rows.
If there is something like a lookup table behinde a Col ... aggregation function, the function uses the same identifier
1) to split rows to different groups for aggregation ("M" / "F"):
Judy is female, the weight in Judy's row should be included in female mean weight
2) as index when reading an entry from the lookup table ("M" / "F"):
Judy is female, the new column should contain female mean weight in Judy's row
So, either male and female get the same values, because the identifier is the same (mean1) - or they get different values because the identifier is different (mean2).
ergo:
A Jmp user can use the GroupBy feature to remove values from the calculation via:
- calculate different values for different subgroups
- dump the unwanted results
but then he gets
- get different values for different subgroups
for free - even if the he did not order this option (OK, the code tells another story - but let's think about what the user wanted)
Is there a one-line command to remove female from the mean calculation, but to write the values into the respective rows with "female"?
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column("mean1", Formula(Col Mean(:weight, :age)));
dt << New Column("mean2", Formula(Col Mean(:weight, :age, :sex)));
dt << New Column("mean2", Formula(If(:sex=="M", Col Mean(:weight, :age, :sex))));
dtM = dt << subset( Rows( dt << get rows where( :sex== "M" ) ), selected columns( 0 ));
dtM << New Column("mean_M", Formula(Col Mean(:weight, :age)));
dt << Update(
With( dtM ),
Match Columns(:age = :age ),
Add Columns from Update Table( :mean_M ),
Replace Columns in Main Table( None )
);