取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
选择语言 隐藏翻译栏
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 个已接受解答

已接受的解答
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

在原帖中查看解决方案

2 条回复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!

推荐文章