cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
chappe
Level II

col mean with byVar argument not running in script

I am trying to use the Col Mean function with 2 additional columns to group by. The formula works perfectly when I manually enter it, but when I copy it into my script and run I get only one (incorrect) number in the first row. If I click in to view the formula and then hit apply the column the properly populates. This seems to be specific to trying to add the byVar argument as my col mean formula will work properly if I remove those. Any ideas on what I am doing wrong? 

This works

 Formula(Col Mean(:RLU))

This doesn't

 Formula(Col Mean( :RLU, :Assay))
4 REPLIES 4
jthi
Super User

Re: col mean with byVar argument not running in script

Are you trying to create formula, use << set each value to fill values in column or use For Each Row?

jthi_0-1675712202158.png

If you are just trying to get mean values based on groups in a script, you will have to use other methods (Summarize for example).

-Jarmo
chappe
Level II

Re: col mean with byVar argument not running in script

The by Var is referencing a column in the same table. I am creating the column and then trying to populate it using the formula which works perfectly when I do it manually but even taking that exact script and pasting it into my larger script doesn't work. If I remove the ":assay" from the formula and run my script, it populates every row (but this is the mean across different groups). 

Re: col mean with byVar argument not running in script

There must be something else going on, as your syntax for Col Mean is OK. For example, the following script works:

Names Default To Here(1);

dt = as table(J(50, 1, randomuniform()), << column names ({"RLU"}) );

dt << new column ("Assay", character, << set values ( words("abcd", "")[J(50, 1, randominteger(1,4))]));

dt << new column ("mean", formula(colmean(:RLU, :Assay)));

You can see that it is computing group means.

brady_brady_0-1675803673716.png

 

When I first ran my code, I forgot to place the column name RLU in curly braces, so the column name was not created properly, and I got an error like the one you described. Perhaps it has something to do with this?

brady_brady_1-1675803764331.png

 

brady_brady_0-1675803890304.png

 

hogi
Level XII

Re: col mean with byVar argument not running in script

Could you please right click on the non-functional formula column  and post the JSL code here. Sometimes it's just a comma or semicolon at the wrong position. If you fix it everything is fine.

 

Which sample data table are you using?