複数のデータテーブルに使用したい一連の標準列があります。問題は、一部のデータテーブルにこれらの列のすべてが含まれていない可能性があることです。
どうすれば簡単にできますか。
1。標準の列のリストを使ってデータテーブルを作成します(例:ES1、ES2、ES3、ES4、ES5)。
2。上記の列の一部を含む可能性のあるデータテーブルを読み込む(例:ES1、ES3)
| | ES1 | ES3 |
| 1行目を数える | 2 | 4 |
| 2行目を数える | 2 | 10 |
3。標準列の全リストを使用して、count#2のデータテーブルのデータテーブルを作成します。
| | ES1 | ES2 | ES3 | ES4 | ES5 |
| 1行目を数える | 2 | 0 | 4 | 0 | 0 |
| 2行目を数える | 2 | 0 | 10 | 0 | 0 |
これを行うには、いくつかの方法があります。
Names Default To Here( 1 );
dt1 = Data Table( "Your first table" );
dt2 = Data Table( "Your second table" );
dt1 << concatenate( dt2 );
Names Default To Here( 1 );
StdNamesList = {"PQrz", "acgh","bddxy","abcd"};
ExistingColNames = dt << get column names;
dt2 = Data Table( "Your second table" );
// If a std name exits in the data table, eliminate it from this working copy of the
// translate data table
For(i=1,i<=ncols(dt),i++,
If(contains(StdNamesList,ExistingColNames[i])
stdNamesList = remove( stdNamesList,contains(StdNamesList,ExistingColNames[i], 1))
)
);
// Add in the missing columns
For(i=1,i<=ncols(dt),i++,
dt2 << New Column(StdNamesList[i],set each value(0));
);こんにちはジム、
連結は一般的な行の値を合計しているようには見えません。例えば、NDP1007の場合、ES3の値は7(シート1、シート1 2の合計)になると予想します。
これを実行できる方法はありますか?
敬具、
ザック

新しい仕様を考えると、問題はもう少し複雑になります。 JMPには組み込みの集計機能はありません。 データの結合に関連して実行したいアクションは非常に多くありますが、合計はデフォルトの項目として設定されません。 以下の簡単なスクリプトは、必要な合計を実行します。 示されているコードの大部分は、サンプルデータテーブルを作成するためのものです。 32〜59行目のコードだけが、データをまとめる作業を行います。
Names Default To Here( 1 );
// Create the sample data tables
dt = New Table( "Primary",
Add Rows( 3 ),
New Column( "Column 1",
Character,
"Nominal",
Set Selected,
Set Values( {"NDP1007", "NDP2024", "NDP3030"} )
),
New Column( "ES1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 2, 1] ) ),
New Column( "ES2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [5, 0, 1] ) ),
New Column( "ES3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [5, 0, 2] ),
Set Display Width( 46 )
),
New Column( "ES4", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 1, 3] ) ),
New Column( "ES5", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 2, 3] ) ),
Set Row States( [0, 1, 0] )
);
dt2 = New Table( "Secondary",
Add Rows( 2 ),
New Column( "Column 1", Character, "Nominal", Set Values( {"NDP1007", "NDP2024"} ) ),
New Column( "ES1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 0] ) ),
New Column( "ES3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3] ) )
);
// Change the names in the Secondary data table so after joining they can be summed together
// and create a list of the new names
newColNameList = {};
For( i = 2, i <= N Cols( dt2 ), i++,
Column( dt2, i ) << set name( (Column( dt2, i ) << get name) || "_X" );
Insert Into( NewColNameList, Column( dt2, i ) << get name );
);
// Update the primary data table with the secondary table
dt << Update( With( dt2 ), Match Columns( :Column 1 = :Column 1 ) );
// Create the code to add the data together that needs to be summed
For( col = 1, col <= N Items( newColNameList ), col++,
// Make sure the standard name is in the data table and if so, add
// the values together
If( Try( Column( dt, Word( -2, newColNameList[col], "_" ) ) << get name ) != "",
For( theRow = 1, theRow <= N Rows( dt ), theRow++,
Column( dt, Word( -2, newColNameList[col], "_" ) )[theRow] = Sum(
Column( dt, Word( -2, newColNameList[col], "_" ) )[theRow],
Column( dt, newColNameList[col] )[theRow]
)
)
)
);
// Delete the Secondary column no longer needed
dt << delete columns( newColNameList ); @ zjuv007 、
ジム、 @txnelson あなたのテーブルを結合するためのキーをあなたに提供しました。共通レコードの合計を取得する最後の手順は、Table Sumaryを実行することです。
以下のスクリプトはJimの最初の解決策を基にしており、すべての数値列のSum()が欲しいと仮定しています。Jimの2番目のスクリプトが示したように、numclistを可能な列のリストになるように変更することをお勧めします。スクリプトとデータテーブルsheet1とsheet2が添付されています。
Names Default To Here( 1 );
dt1 = Data Table( "sheet1" );
dt2 = Data Table( "sheet2" );
dt3 = dt1 << concatenate( dt2 );
numclist = dt1 << Get Column Names(Numeric, String);
sumXP = Expr(Summary(
Group( :Column 1 ),
Weight( "None" ),
statistics column name format( "column" ),
Link to original data table( 0 ),
Output Table Name ("Summed Table")
) );
for(i=1, i<=nitems(numclist), i++,
Insert Into(sumXP, EvalExpr(Sum(Column(Expr(numclist[i])))))
);
show(NameExpr(sumXP) );
Eval (EvalExpr(dt3 << expr(sumXP) ) );
dt = Data Table( "Summed Table" );
//option
dt << delete column( {"N Rows"});

あなたがそのような質問に従うことを尋ねる前に、あなたは供給された答えを研究する必要があります、それであなたはそれがどのように働くか理解します。文を理解していれば
dt3 = dt1 << concatenate( dt2 );
そして、Scripting GuideまたはScripting Indexで調べてみると、1つのステートメントに必要なだけの数のデータテーブルを連結することができます。
あなたの2番目の質問に関しては、行を変更する
numclist = dt1 << Get Column Names(Numeric, String);
に
numclist = dt3 << Get Column Names(Numeric, String);
すべてのデータテーブルで見つかったすべての列の完全なリストが表示されます。 その組み合わせたリストを使うことがあなたが必要とする答えかもしれません