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

Copying selected cells from one column and pasting them into selected cells in another column

Hello, I am a JSL beginner. I need to learn how to move a block of cells in one column to a different location in a different, newly created column.  In this case, on top of this new column.

 

Specifically, I need to select a set of cells in column THK marked as PRE in a separate PRE/POST column, and paste them on top of a new column marked THK PRE. It is somewhat similar to the Split Column function, but I do not want to use the Split Column function as I find that, due to some glitch, the data sometimes appears scrambled in the newly created column if the data in some cells of the THK column is missing.

 

From some examples on the forums, I put together the code below, but it does not paste any values in the newly created THK PRE column.  Please help!  Many thanks in advance.

 

Here's what I need:

 

Starting data table

 

THK     I    PRE/POST 

9.5            POST

9.8            POST

10.1          POST

11.0           PRE

11.4          PRE

10.9          PRE

 

Here's what I need the data table to look like after this operation:

 

THK     |     PRE/POST   |   THK PRE

9.5            POST                 11.0

9.8            POST                 11.4

10.1         POST                  10.9

11.0          PRE

11.4          PRE

10.9          PRE

 

The script below does not paste any values in the newly created column, the column remains empty

 

 

// Pick the source data table
dt=Open("Data Table");

//Create New THK PRE column
dt << New Column( "THK PRE", Numeric, "Continuous");
Wait(1);


// Select PRE values from THK column
vals = Column(dt, "THK") << Get Rows Where(:Name("PRE/POST") == "PRE");

// Put these in the new column THK PRE
Column(dt, "THK PRE") << Set Values(vals)

 

 

Please help! Many thanks in advance.  I use JUMP 16.0.0

 

@jthi 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Copying selected cells from one column and pasting them into selected cells in another column

Here is a rework of your script with some added annotation that handles what you want

Names Default To Here( 1 );

// Pick the source data table
//dt=Open("Data Table");
dt = New Table( "Example",
	Add Rows( 6 ),
	New Column( "THK",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [9.5, 9.8, 10.1, 11, 11.4, 10.9] )
	),
	New Column( "PRE/POST",
		Character,
		"Nominal",
		Set Values( {"POST", "POST", "POST", "PRE", "PRE", "PRE"} )
	)
);

//Create New THK PRE column
dt << New Column( "THK PRE", Numeric, "Continuous" );
Wait( 0 );


// Find the rows PRE values from THK column
// and copy those values from the found rows
// to the vals matrix 
vals = :THK[dt << get rows Where( :Name( "PRE/POST" ) == "PRE" )];

// Put these in the new column THK PRE
dt:THK PRE << Set Values( vals );
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Copying selected cells from one column and pasting them into selected cells in another column

Here is a rework of your script with some added annotation that handles what you want

Names Default To Here( 1 );

// Pick the source data table
//dt=Open("Data Table");
dt = New Table( "Example",
	Add Rows( 6 ),
	New Column( "THK",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [9.5, 9.8, 10.1, 11, 11.4, 10.9] )
	),
	New Column( "PRE/POST",
		Character,
		"Nominal",
		Set Values( {"POST", "POST", "POST", "PRE", "PRE", "PRE"} )
	)
);

//Create New THK PRE column
dt << New Column( "THK PRE", Numeric, "Continuous" );
Wait( 0 );


// Find the rows PRE values from THK column
// and copy those values from the found rows
// to the vals matrix 
vals = :THK[dt << get rows Where( :Name( "PRE/POST" ) == "PRE" )];

// Put these in the new column THK PRE
dt:THK PRE << Set Values( vals );
Jim
BladeRunner
Level II

Re: Copying selected cells from one column and pasting them into selected cells in another column

Hello Txnelson, many thanks for the quick response!  Works like a charm!   I guess I was pretty close, but couldn't quite figure our the syntax.