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
gmc5149
Level I

How do I create a new data table combining duplicate rows?

I have a indexed list of production runs of different products (A-H) and their start and end times. Sometimes there are two lines in a row with the same product (rows 1 & 2 and 7 & 8) and I would like those to be combined into one row with the start time of the first row and end time of the second row. How would I use JSL to do this?

 

gmc5149_0-1713457204801.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do I create a new data table combining duplicate rows?

I think this should do what you want.

 

Add new (numeric) column to your table to calculate "groups" with formula like

If(Row() == 1,
	counter = 0;
);
If(:Product != Lag(:Product),
	counter++;
);
counter;

Then you can use Summary table to perform the min/max part

jthi_1-1713458056939.png

Remove and re-order columns from summary table as needed

 

Here is a script from Enhanced Log to perform those actions

 

// Open Data Table: Run Time Index.jmp
// → Data Table("Run Time Index")
Open("$DOWNLOADS/Run Time Index.jmp");

// New column: R
Data Table("Run Time Index") << New Column("R",
	Numeric,
	"Continuous",
	Format("Best", 12),
	Formula(
		If(Row() == 1, counter = 0);
		If(:Product != Lag(:Product),
			counter
			++);
		counter;
	)
);

// Data table summary
// → Data Table("Run Time Index By (R, Product)")
Data Table("Run Time Index") << Summary(
	Group(:R, :Product),
	Min(:Run Index),
	Min(:Start),
	Max(:End),
	Freq("None"),
	Weight("None"),
	statistics column name format("column"),
	Link to original data table(0)
);

// Delete columns
Data Table("Run Time Index By (R, Product)") << Delete Columns(:R, :N Rows);

// Move selected column: Run Index
Data Table("Run Time Index By (R, Product)") << Move Selected Columns({:Run Index}, To First);

// Change column modeling type: Run Index
Data Table("Run Time Index By (R, Product)"):Run Index << Set Modeling Type("Ordinal");

 

 

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: How do I create a new data table combining duplicate rows?

I think this should do what you want.

 

Add new (numeric) column to your table to calculate "groups" with formula like

If(Row() == 1,
	counter = 0;
);
If(:Product != Lag(:Product),
	counter++;
);
counter;

Then you can use Summary table to perform the min/max part

jthi_1-1713458056939.png

Remove and re-order columns from summary table as needed

 

Here is a script from Enhanced Log to perform those actions

 

// Open Data Table: Run Time Index.jmp
// → Data Table("Run Time Index")
Open("$DOWNLOADS/Run Time Index.jmp");

// New column: R
Data Table("Run Time Index") << New Column("R",
	Numeric,
	"Continuous",
	Format("Best", 12),
	Formula(
		If(Row() == 1, counter = 0);
		If(:Product != Lag(:Product),
			counter
			++);
		counter;
	)
);

// Data table summary
// → Data Table("Run Time Index By (R, Product)")
Data Table("Run Time Index") << Summary(
	Group(:R, :Product),
	Min(:Run Index),
	Min(:Start),
	Max(:End),
	Freq("None"),
	Weight("None"),
	statistics column name format("column"),
	Link to original data table(0)
);

// Delete columns
Data Table("Run Time Index By (R, Product)") << Delete Columns(:R, :N Rows);

// Move selected column: Run Index
Data Table("Run Time Index By (R, Product)") << Move Selected Columns({:Run Index}, To First);

// Change column modeling type: Run Index
Data Table("Run Time Index By (R, Product)"):Run Index << Set Modeling Type("Ordinal");

 

 

-Jarmo
gmc5149
Level I

Re: How do I create a new data table combining duplicate rows?

thank you!

txnelson
Super User

Re: How do I create a new data table combining duplicate rows?

 

 

 

Jim

Recommended Articles