cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

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

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 IX

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 IX

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 IX

Re: Can this formula be completed in one step?

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

Recommended Articles