Add Column Data from One Table to Already Existing TableHi,
I am trying to add column data from one output table (called "output") to an EXISTING TABLE (called "Stanmore and Lam"), but when I use the join command it creates an empty new output table. My code is as follows:
output = New Table( "Output",
AddRows( 1 ),
New Column( "Y (coronal) mm", Numeric, Continuous ),
New Column( "X (sagittal) mm", Numeric, Continuous )
);
:"Y (coronal) mm" << addRows( 1 );
:"X (sagittal) mm" << addRows( 1 );
:"Y (coronal) mm"[1] = ymax;
:"X (sagittal) mm"[1] = xmax;
dt2 = Open( "Stanmore and Lam.jmp" );
dt2 << Join(
With( Data Table( output ) ),
By Matching Columns( :"Y (coronal) mm" = :"Y (coronal) mm", :"X (sagittal) mm" = :"X (sagittal) mm" )
);
Is there any way to simply add row values in a specific column to a pre-existing column (both tables have different numbers of columns and rows) without manually entering the data from one table to another? Thanks!
Noah
Re: Add Column Data from One Table to Already Existing TableI was able to set a reference by adding the following to the code you proposed above:
toBeConcat = dt2 << Join(
With( Data Table( output ) ),
"Stanmore and Lam",
Update,
By Matching Columns(
:Name( "Y (coronal) mm" ) = :Name( "Y (coronal) mm" ),
:Name( "X (sagittal) mm" ) = :Name( "X (sagittal) mm" )
)
);
dt2 << Concatenate( toBeConcat, append to first table );
This 1) updates the format of my output to fit that of the Stanmore and Lam table and 2) concatenates that output to the original table without creating a new output data table. So now the code does exactly what I need it to. Thanks so much for your help!
Re: Add Column Data from One Table to Already Existing TableMy comment on the "UPDATE" option will handle that. Just add
Update,
to your Join, and it will handle what you want.
Re: Add Column Data from One Table to Already Existing TableThanks for the quick reply! This syntax works much better for populating a new table with the values I need. This still produces an entirely new table, so is there any way that I can set a reference to it so that I may concatenate it to my "Stan and Lanmore" table? Thanks again!
Noah
Re: Add Column Data from One Table to Already Existing TableHere is a rework of your script, to make it syntactially proper. I can not speak to your logic, since you did not include what your variables xmax and ymax are, nor what the data table "Stanmore and Lam" contains
output = New Table( "Output",
AddRows( 1 ),
New Column( "Y (coronal) mm", Numeric, Continuous ),
New Column( "X (sagittal) mm", Numeric, Continuous )
);
// You don't add rows to columns, you add rows to data tables. But since you have allready added
// a row to the new data table, you don't need to add a second row
//:"Y (coronal) mm" << addRows( 1 );
//:"X (sagittal) mm" << addRows( 1 );
// The proper form for what you are trying to do is:
// :Name("complex name")
//:"Y (coronal) mm"[1] = ymax;
//:"X (sagittal) mm"[1] = xmax;
:Name("Y (coronal) mm")[1] = ymax;
:Name("X (sagittal) mm")[1] = xmax;
dt2 = Open( "Stanmore and Lam.jmp" );
dt2 << Join(
With( Data Table( output ) ),
// You may want to use the "UPDATE" option to copy the matching rows from the joining table to the
// initial table
// Update,
// The proper naming structure has been replaced here too
By Matching Columns( :Name("Y (coronal) mm") = :Name("Y (coronal) mm") , :Name("X (sagittal) mm") = :Name("X (sagittal) mm") )
);