cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

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

Calculate time difference and summing the values

I have a table with a time column with this format: m/d/y h:m:s

I would like to create a new column called CumTimeSec that will show the cumulative time difference up to that row.

For example,

Time

 

TimeCumTimeSec

5/11/2022 5:30:03 PM

0

5/11/2022 5:30:08 PM

5
5/11/2022 5:30:20 PM17
5/11/2022 5:30:23 PM 20

 

I figured I could use this code to calculate the difference between each row, but I'm not sure how to sum the values

dt << New Column( "CumTimeSec",
	Numeric,
	"Continuous",
	formula(  :Time - Lag( :Time) )
);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jasean
Staff

Re: Calculate time difference and summing the values

Hi Lavik17,

 

Lag is useful for this application, but you need to use it a couple of times.  Note that Dif() takes the difference between the current row and a "lag" row.  For example, above you calculate :Time - Lag(:Time).  That is the same as Dif(:Time).

 

Here is an example you can run with JMP sample data.  The table just lists a sequence of years, but it will work the same for a time column.

dt = Open("$SAMPLE_DATA/Time Series/SeriesQ.jmp");
dt << New Column("CumTimeYear", Formula(
	If( Row() > 1,
		Lag( :CumTimeYear ) + Dif( :Year )
	, // else first row
		0
	)
));

View solution in original post

3 REPLIES 3
Jasean
Staff

Re: Calculate time difference and summing the values

Hi Lavik17,

 

Lag is useful for this application, but you need to use it a couple of times.  Note that Dif() takes the difference between the current row and a "lag" row.  For example, above you calculate :Time - Lag(:Time).  That is the same as Dif(:Time).

 

Here is an example you can run with JMP sample data.  The table just lists a sequence of years, but it will work the same for a time column.

dt = Open("$SAMPLE_DATA/Time Series/SeriesQ.jmp");
dt << New Column("CumTimeYear", Formula(
	If( Row() > 1,
		Lag( :CumTimeYear ) + Dif( :Year )
	, // else first row
		0
	)
));
jthi
Super User

Re: Calculate time difference and summing the values

Haven't used Dif before but you could combine it Col Cumulative Sum

Col Cumulative Sum(Dif(:Time))
-Jarmo
Lavik17
Level III

Re: Calculate time difference and summing the values

Thanks @Jasean !! Worked like a charm!!

Recommended Articles