cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Ksrzg01
Level I

Evaluating Col Mean with Iterations

Hi everyone, 

 

I'm having trouble evaluating a col mean function. As you can see below, the col mean(:age, :list_col_names[i]] doesnt insert the item in the list on the data table. With this current configuration, when I open the formula on the data table I get "Col Mean( :age, list_col_names[i] )" which doesnt correspond to anything on the list_col_names list.

list_col_names = fdt << getColumnNames( "String" );

For( j = N Items( list_col_names ), j > 0, j--,
	If( Left( list_col_names[j], 2 ) != "10",
		Remove From( list_col_names, j )
	)
);

For( i = 1, i <= N Items( list_col_names ), i++,
fdt << New Column( list_col_names[i] || "_age", Numeric, Formula( Col Mean( :age, :list_col_names[i] ) ) )
);

on in an iteration

1 ACCEPTED SOLUTION

Accepted Solutions
vince_faller
Super User (Alumni)

Re: Evaluating Col Mean with Iterations

you can't do :list_col_names[i], You're explicitly stating that you have a column called "list_col_names" and you're pulling the ith row of it.  

 

Try this

 

Names Default to here(1);
fdt = open("$SAMPLE_DATA\Big Class.jmp");
list_col_names = {"sex", "name"};

For( i = 1, i <= N Items( list_col_names ), i++,
	//this is just it doesn't keep the variable 
	//in the table because i will change and then your column name will change
	Eval(
		EvalExpr(
			fdt << New Column( list_col_names[i] || "_age", 
				Numeric, 
				Formula( Col Mean( :age, 
					//replaces the string column name with an actual column
					Expr(Column(fdt, list_col_names[i]))
						
				) ) 
			)
		)
	)
);
Vince Faller - Predictum

View solution in original post

2 REPLIES 2
vince_faller
Super User (Alumni)

Re: Evaluating Col Mean with Iterations

you can't do :list_col_names[i], You're explicitly stating that you have a column called "list_col_names" and you're pulling the ith row of it.  

 

Try this

 

Names Default to here(1);
fdt = open("$SAMPLE_DATA\Big Class.jmp");
list_col_names = {"sex", "name"};

For( i = 1, i <= N Items( list_col_names ), i++,
	//this is just it doesn't keep the variable 
	//in the table because i will change and then your column name will change
	Eval(
		EvalExpr(
			fdt << New Column( list_col_names[i] || "_age", 
				Numeric, 
				Formula( Col Mean( :age, 
					//replaces the string column name with an actual column
					Expr(Column(fdt, list_col_names[i]))
						
				) ) 
			)
		)
	)
);
Vince Faller - Predictum
Ksrzg01
Level I

Re: Evaluating Col Mean with Iterations

Works great. Thank you Vince!

Recommended Articles