cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

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