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
mostarr
Level IV

Updating Part of a Data Table by Row and Column Using JSL

Hi, sorry, I've been Googling for hours now and I just don't know what to do. I don't know how to formulate my question though I will try my best, it's just, really exasperating and getting to me now, finally, how such a simple thing can be so complicated. I see that JMP is intended for some things and not others, after all. In Python this would be very easy for me. But I guess it's all about experience. Not to add insult to injury.

 

I wish to replace a subset of my data table with new data. I have the target rows and target column and the old table and the new data. What is the syntax to do this?

 

Thank you.

Michael

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Updating Part of a Data Table by Row and Column Using JSL

Here are 3 ways to update data in one table, with values from another table.

Names Default To Here( 1 );

// Open Data Table: big class.jmp
// → Data Table( "big class" )
Open( "$SAMPLE_DATA/big class.jmp" );

// Create a table with values to be input
// into the big class table
New Table( "Using Update",
	New Column( "Name", character, values( {"JANE", "TIM", "ALICE"} ) ),
	New Column( "Height", values( {58, 69, 64} ) ),
	New Column( "Weight", values( {88, 100, 120} ) )
);

// Wait for a short time to be able to see the two
// data tables before combining them
Wait( 5 );

// Update data tables
Data Table( "big class" ) << Update( With( Data Table( "Using Update" ) ), Match Columns( :name = :Name ) );

// Update a block of data into the data table
// Create a table to get values from
New Table( "Just Data",
	New Column( "A", values( {100, 101, 102, 103} ) ),
	New Column( "B", values( {90, 91, 92, 93} ) )
);

// Wait for a short time to be able to see the two
// data tables before combining them
Wait( 5 );

dt = Data Table( "big class" );
dt2 = Data Table( "Just Data" );

dt[3 :: 6, 4 :: 5] = dt2[1 :: 4, 1 :: 2];

// One last simple way to move data
dt:age[2] = dt2:a[4];
Jim

View solution in original post

Re: Updating Part of a Data Table by Row and Column Using JSL

Hi Michael,

 

I've attached a script I wrote many moons ago to illustrate some commonly-used syntax for table operations. When you're checking it out, turn on your log so you can see results, and run each line one at a time. If you go out of order it may not work properly as sometimes I do things that rely on previously executed code.

 

In your specific case, you can replace table contents using subscripting... have a look at this script, running things line-by-line

 

names default to here(1);

//create a 10x10 table of random integers between 1 and 20
dt = As Table( J( 10, 10, Random Integer( 1, 20 ) ) );

//replace column 1 with fibonacci numbers... note 0th row means ALL rows
//note that ` is the transpose operator. 
dt[0, 1] = (Round( 1 / Sqrt( 5 ) * ((1 + Sqrt( 5 )) / 2) ^ (1 :: 10) ))` ;

//replace a subbloc of the table with numbers 81-100 in a 4x5 shape
dt[3::6, 4::8] = shape(81::100, 4);

//set a subbloc to all zeros
dt[8::10, 2::4] = 0;

//store a cell's value in a variable
x = dt[2,3];

//store a subbloc in a matrix
mat = dt[4::6, 0];

//set the whole table to missing
dt[0,0] = .;

 

 

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Updating Part of a Data Table by Row and Column Using JSL

Here are 3 ways to update data in one table, with values from another table.

Names Default To Here( 1 );

// Open Data Table: big class.jmp
// → Data Table( "big class" )
Open( "$SAMPLE_DATA/big class.jmp" );

// Create a table with values to be input
// into the big class table
New Table( "Using Update",
	New Column( "Name", character, values( {"JANE", "TIM", "ALICE"} ) ),
	New Column( "Height", values( {58, 69, 64} ) ),
	New Column( "Weight", values( {88, 100, 120} ) )
);

// Wait for a short time to be able to see the two
// data tables before combining them
Wait( 5 );

// Update data tables
Data Table( "big class" ) << Update( With( Data Table( "Using Update" ) ), Match Columns( :name = :Name ) );

// Update a block of data into the data table
// Create a table to get values from
New Table( "Just Data",
	New Column( "A", values( {100, 101, 102, 103} ) ),
	New Column( "B", values( {90, 91, 92, 93} ) )
);

// Wait for a short time to be able to see the two
// data tables before combining them
Wait( 5 );

dt = Data Table( "big class" );
dt2 = Data Table( "Just Data" );

dt[3 :: 6, 4 :: 5] = dt2[1 :: 4, 1 :: 2];

// One last simple way to move data
dt:age[2] = dt2:a[4];
Jim

Re: Updating Part of a Data Table by Row and Column Using JSL

Hi Michael,

 

I've attached a script I wrote many moons ago to illustrate some commonly-used syntax for table operations. When you're checking it out, turn on your log so you can see results, and run each line one at a time. If you go out of order it may not work properly as sometimes I do things that rely on previously executed code.

 

In your specific case, you can replace table contents using subscripting... have a look at this script, running things line-by-line

 

names default to here(1);

//create a 10x10 table of random integers between 1 and 20
dt = As Table( J( 10, 10, Random Integer( 1, 20 ) ) );

//replace column 1 with fibonacci numbers... note 0th row means ALL rows
//note that ` is the transpose operator. 
dt[0, 1] = (Round( 1 / Sqrt( 5 ) * ((1 + Sqrt( 5 )) / 2) ^ (1 :: 10) ))` ;

//replace a subbloc of the table with numbers 81-100 in a 4x5 shape
dt[3::6, 4::8] = shape(81::100, 4);

//set a subbloc to all zeros
dt[8::10, 2::4] = 0;

//store a cell's value in a variable
x = dt[2,3];

//store a subbloc in a matrix
mat = dt[4::6, 0];

//set the whole table to missing
dt[0,0] = .;

 

 

Recommended Articles