cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Arocha1
Level I

Reorganizing A Table by Items Within A Column

Hello,

 

I have a system that calibrates data and outputs the information as so:

Tire IDTreadDepthDraguSpsi
2326Inner0.6185840.1177740.41731421.15549
2326Outer0.7408410.4170790.41731421.15549
2327Inner0.3290650.2189030.36507125.65573
2327Outer0.4780550.2149530.36507125.65573

 

The Tire ID is read twice, once for the inner tread readings, and once for the outside. Is there a script I can use to reorganize it as such:

Tire IDInner DepthOuter DepthInner DragOuter DraguSpsi
23260.618584450.740840570.11777370.41707940.4173121.1555
23270.329064510.478055450.21890250.21495270.3650725.6557

 

Here, there is only one entry per tire. The entries for Depth and Drag have been renamed by Inner or Outer and the identical columns have just been merged into one. This is a snip of a much larger sheet with many more columns - some different, others the same.

 

Ideally, the script can determine what cells are the same according to tired ID and just remove replicates. But a script that's set up with predetermined names could work too, since the column names never change.

 

Thank you!

 

@jthi@txnelson , you two helped tremendously last time! Thank you for that! I don't really know what approach to take and haven't been able to find anything similar enough in previous solutions.

3 REPLIES 3
pmroz
Super User

Re: Reorganizing A Table by Items Within A Column

This is a brute-force approach, but it works.  Note the variables for split columns and nonsplit columns.

dt = New Table( "Base Tire Data", Add Rows( 4 ),
	New Column( "Tire ID", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [2326, 2326, 2327, 2327] ) ),
	New Column( "Tread", Character( 16 ), "Nominal",
		Set Values( {"Inner", "Outer", "Inner", "Outer"} ) ),
	New Column( "Depth", Numeric, "Continuous", Format( "Best", 12 ), 
		Set Values( [0.618584, 0.740841, 0.329065, 0.478055] ) ),
	New Column( "Drag", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [0.117774, 0.417079, 0.218903, 0.214953] ) ),
	New Column( "uS", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [0.417314, 0.417314, 0.365071, 0.365071] ) ),
	New Column( "psi", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [21.15549, 21.15549, 25.65573, 25.65573] ) )
);

nr = nrows(dt);

dtt = New Table( "Split Tires");
dtt << new column("Tire ID", Numeric, "Continuous", Format( "Best", 12 ));

split_cols = {"Depth", "Drag"};
nonsplit_cols = {"uS", "psi"};

for (i = 1, i <= nitems(split_cols), i++,
	inn_col = "Inner " || split_cols[i];
	out_col = "Outer " || split_cols[i];
	dtt << new column(inn_col, Numeric, "Continuous", Format( "Best", 12 ));
	dtt << new column(out_col, Numeric, "Continuous", Format( "Best", 12 ));
);

for (i = 1, i <= nitems(nonsplit_cols), i++,
	one_col = nonsplit_cols[i];
	dtt << new column(one_col, Numeric, "Continuous", Format( "Best", 12 ));
);

dtt << Add Rows( nr/2 );

k = 0;
for (i = 1, i <= nr, i+=2,
	k++;
	for (m = 1, m <= nitems(split_cols), m++,
		one_col = split_cols[m];
		inn_col = "Inner " || split_cols[m];
		out_col = "Outer " || split_cols[m];

		column(dtt, inn_col)[k] = column(dt, one_col)[i];
		column(dtt, out_col)[k] = column(dt, one_col)[i+1];
	);

	column(dtt, "Tire ID")[k] = column(dt, "Tire ID")[i];

	for (m = 1, m <= nitems(nonsplit_cols), m++,
		one_col = nonsplit_cols[m];
		column(dtt, one_col)[k] = column(dt, one_col)[i];
	);
);
txnelson
Super User

Re: Reorganizing A Table by Items Within A Column

What you are asking for is available by using the Split platform

     Tables=>Split

After you open the Split platform, setup the screen as shown below

txnelson_0-1646193416139.png

Once you click OK, it will create a new data table

txnelson_1-1646193468096.png

The script to perform the Split is contained in the Source entry of the data table

Just right click on the word Source

txnelson_2-1646193598384.png

and select Edit

The Edit window will open and show the JSL required to run the Split and create the data table you want.

txnelson_3-1646193743909.png

Just cut and paste the JSL from the Edit window, into your script

Jim
pmroz
Super User

Re: Reorganizing A Table by Items Within A Column

Nice Jim!  Much better than my brute force approach.  I would add uS and psi to the Group columns as per @Arocha1 's request.

pmroz_0-1646221599613.png

pmroz_1-1646221658762.png