単一行の更新をエレガントに実行するにはどうすればよいでしょうか?こんにちは - あるテーブルから行を取得し、ユーザーが入力ボックスで指定した行にある別のテーブルにそれをスローしようとしています。 ただし、update 関数には行を指定する機能がないようなので、1 時間かけて両方のデータ テーブルの 105 列をそれぞれ次のように入力することになります。
dt:{"ColA"}[rownumber] = dt1:{"ColA"}[1];<BR />dt:{"ColB"}[rownumber] = dt1:{"ColB"}[1];<BR />.<BR />.<BR />.<BR />dt:{"ColDA"}[rownumber] = dt1:{"ColDA"}[1];それはそれでいいのですが、コーディング仲間がそれを見て席で身悶えしているのが想像できます。 これを行うよりエレガントな方法はありますか? 誰かが連想配列を参照しているのを見たことがありますが、それを使用するのに問題があります。
上記のコードで十分だと思いますが、重要な場合は、関連する線が赤で描かれた元のコードを次に示します。
w = New Window( "Choose Row Number for XRD Run input", // opens a window with a title and this content...
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
V List Box( // V and H lists nest to organize the display boxes
H Center Box( Text Box( "Choose Row Number for XRD Run input" ) ), // a second title, centered
Spacer Box( size( 1, 30 ) ), // a little vertical space
H Center Box( rowtemp=Number Edit Box( ) ), // data entry
Spacer Box( size( 1, 10 ) ), // a little vertical space
H Center Box( // center the button
Button Box( "Import Data", // this script runs when the button is pressed...
rownumber = rowtemp << Get;
// Run XML Import
Include( "jmpprj://contents/Import XRD XML.jsl");
// Reference Data Tables
dt = Data Table( "Experimental Info" );
dt1 = Data Table( "XMLTempTable" );
// Move to Experimental info table
<FONT color="#FF0000">dt:{"xsi:Schema Location 1"}[rownumber] = dt1:{"xsi:Schema Location 1"}[1];</FONT>
// Close XMLTempTable
close(dt1);
// optionally, close the dialog. Or, you might want to run it again...
w << closeWindow; // just the dialog, not the report
)
)
)
)
);自動化とスクリプト作成ウィンドウズRe: 単一行の更新をエレガントに実行するにはどうすればよいですか?ここでは、単一行の更新を行う 1 つの方法を示します。1 つのデータ テーブルから指定された行を取得し、それを別のデータ テーブルの指定された行に更新します。
names default to here(1);
dt=
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
// Create a random data table with 5 rows
// Subset data table
// → Data Table( "Subset of Big Class" )
dt2 = dt << Subset( Sample Size( 5 ), Selected columns only( 0 ), output table("Selection") );
// Give new names to the subsetted table
dt2:name[1] = "PAT";
dt2:name[2] = "BRIT";
dt2:name[3] = "TERRY";
dt2:name[4] = "KRIS";
dt2:name[5] = "JEN";
wait(10);
// Below is the code that does the 1 row update
// Row in data table Big Class to be updated
outRow = 12;
// Row in data table Selection to get data from
inRow = 4;
// The Update process
// Create a row column in data table Big Class
dt << new column( "Row", formula(row()));
// Subset the inRow to a new table
dt2 << select where(row()== inRow);
dtTemp = dt2 << subset(selected rows(1), selected columns(0), invisible);
// Clear selected row in data table Selection
dt2 << clear select;
// Create a new column in the temp data table
dtTemp << new column("Row", set each value(outRow));
// Update data table Big Class
dt << Update(
With( dtTemp ),
Match Columns( :Row = :Row )
);
// Delete the temp data table
close( dtTemp, nosave );
// Delete the Row Column
dt << delete columns( :Row );
Re: 単一行の更新をエレガントに実行するにはどうすればよいですか?両方のテーブルに名前や年齢などの一意の識別子がある場合は、それらを一致条件として使用できます。
さらに、仮想変換列を使用することもできます。行の選択更新する行を選択するための追加の一致条件を提供するには、次のようにします。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Namespace(
"selection"
);
selection:ChangeRows = [5, 2, 7];
updateTable = dt << Subset( All rows, Selected columns only( 0 ) );
:weight << set each value( 1000 );
dt << Update(
With( updateTable ),
Match Columns(
:name = :name,
:age = :age,
transform column( "row selection", Formula( If( N Items( Loc( selection:ChangeRows, Row() ) ), 1, . ) ) ) =
transform column( "row selection", Formula( 1 ) )
),
Add Columns from Update Table( None ),
Replace Columns in Main Table( :weight )
);