cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
lala
Level VIII

Can this formula be completed in one step?

I tried, but failed

Thanks Experts!

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
ca = "A";New Column( ca );
Column( ca ) << Formula( height / Lag( height, 5 ) > 1.1 );
dt << run formulas;
Column( ca ) << deleteFormula;
ca = "SumA";New Column( ca );
Column( ca ) << Formula( Sum( A[Index( Row() - 9, Row() )] ) );
dt << run formulas;
Column( ca ) << deleteFormula;
ca = "Sum1";New Column( ca );
Column( ca ) << Formula( Sum( height[Index( Row() - 9, Row() )] / height[Index( Row() - 9 - 5, Row() - 5 )] > 1.1 ) );
dt << run formulas;
Column( ca ) << deleteFormula;//??

2024-07-10_9-54-42.png

1 ACCEPTED SOLUTION

Accepted Solutions
lala
Level VIII

Re: Can this formula be completed in one step?

4 REPLIES 4
jthi
Super User

Re: Can this formula be completed in one step?

What is the formula supposed to do and is there a specific reason to try and force it to be a single step? 

 

-Jarmo
txnelson
Super User

Re: Can this formula be completed in one step?

Here is one way to do it

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
ca = "A";
New Column( ca, set each value( :height / Lag( :height, 5 ) > 1.1 ) );
ca = "SumA";
New Column( ca, set each value( Sum( :A[Index( Row() - 9, Row() )] ) ) );
ca = "Sum1";
New Column( ca,
	set each value(
		As Constant(
			a = [];
			For( i = 1, i <= N Rows( Current Data Table() ), i++,
				If( i > 5,
					a = a || ((:height[i] / :height[i - 5]) > 1.1),
					a = a || .
				)
			);
		);
		If( Row() > 5,
			Sum( A[Index( Max(6,Row() - 9), Row() )], . )
		);
	)
);

 Here is another way

ca = "Sum1a";
New Column( ca,
	set each value(
		If( Row() <= 5,
			val = .,
			theRows = Index( Max( 6, Row() - 9 ), Row() );
			val = .;
			For Each( {calc}, theRows,
				val = Sum( val, (:height[calc] / :height[calc - 5]) > 1.1 )
			);
		);
		val;
	)
);
Jim
lala
Level VIII

Re: Can this formula be completed in one step?

Thank Jim!

OK、

It's a formula I forgot and got in the community before.

Now think of it, it is OK:

ca = "Sum1";New Column( ca );
Column( ca ) << Formula( Sum( height[Index( Row() - 9, Row() )]  height[Index( Row() - 9 - 5, Row() - 5 )] > 1.1 ) );
dt << run formulas;
Column( ca ) << deleteFormula;

 

lala
Level VIII

Re: Can this formula be completed in one step?

2024-07-10_12-50-57.png