我有一组标准列,我想用于多个数据表,问题是某些数据表可能不包含所有这些列。
我怎么能简单地说:
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);
将为您提供所有数据表中找到的所有列的完整列表。 使用该组合列表可能是您需要的答案