我有一組標準列,我想用於多個數據表,問題是某些數據表可能不包含所有這些列。
我怎麼能簡單地說:
1。使用這些標準列列表創建數據表(例如:ES1,ES2,ES3,ES4,ES5)
2。讀取可能包含上述部分列的數據表(例如:ES1,ES3)
3。使用標準列的完整列表創建#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(Sheet 1,Sheet 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()。您可能希望將numclist修改為可能列的列表,正如Jim的第二個腳本所示。附加腳本和數據表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 );
並在“腳本指南”或“腳本索引”中查找,您將看到可以根據需要在一個語句中將多個數據表連接在一起。
關於你的第二個問題,改變線
numclist = dt1 << Get Column Names(Numeric, String);
至
numclist = dt3 << Get Column Names(Numeric, String);
將為您提供所有數據表中找到的所有列的完整列表。 使用該組合列表可能是您需要的答案