여러 데이터 테이블에 사용하려는 표준 열 집합이 있는데 일부 데이터 테이블에는 이러한 열이 모두 포함되어 있지 않을 수도 있습니다.
어떻게 간단하게 할 수 있습니까?
1. 표준 열 목록 (예 : ES1, ES2, ES3, ES4, ES5)을 사용하여 데이터 테이블 만들기
2. 위 열의 일부를 포함 할 수있는 데이터 테이블을 읽습니다 (예 : ES1, ES3).
| | ES1 | ES3 |
| 카운트 라인 1 | 2 | 4 |
| 카운트 라인 2 | 2 | 10 |
삼. 표준 열의 전체 목록으로 # 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 , 당신의 테이블을 결합하는 열쇠를 제공했습니다. 공통 레코드의 합계를 얻는 마지막 단계는 테이블 Sumary를 실행하는 것입니다.
아래 스크립트는 Jim의 첫 번째 솔루션을 기반으로하며 모든 숫자 열의 Sum ()을 원한다고 가정합니다. Jim의 두 번째 스크립트에서 설명한 것처럼 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에서 찾아 보면 한 문장으로 많은 데이터 테이블을 원하는만큼 연결할 수 있다는 것을 알 수 있습니다.
두 번째 질문에 대해서는
numclist = dt1 << Get Column Names(Numeric, String);
에
numclist = dt3 << Get Column Names(Numeric, String);
모든 데이터 테이블에서 찾을 수있는 모든 열의 전체 목록을 제공합니다. 그 결합 된 목록을 사용하면 필요한 대답 일 수 있습니다.