1-209로 표시된 209 개의 열이 포함 된 템플릿 데이터 프레임이 있습니다. 종종 클라이언트는 열이 결합 된 데이터 세트를 전달합니다. 예를 들어, 열 2는 새 데이터 세트에서 열 3 ( '2 + 3'으로 표시됨)과 함께 추가 될 수 있습니다.
새 데이터 세트에서 열을 추출하고이를 수식으로 사용하여 템플릿 데이터 프레임에서 열을 동일하게 만들려면 어떻게해야합니까? JMP에 결합 기능이 있다는 것을 알고 있지만 모든 열 이름을 추출하고이를 수식으로 변환하여 두 데이터 세트를 정렬하는 스크립트를 어떻게 작성할 수 있습니까?
이 이메일에 템플릿 및 대상 데이터 세트가 어떻게 보이는지 첨부했습니다.
다음은 결합 된 열에서 확장되는 간단한 스크립트입니다.참고 : 템플릿 데이터 테이블의 열 이름에 오류가 있습니다.열 이름 95가 두 번 나타납니다.두 번째는 98입니다.
Names Default To Here( 1 );
// Point to the 2 data tables....assumption is they are open
dtTemplate = Data Table( "Template_Template" );
dtTarget = Data Table( "Target_Target" );
// Create a template data table with just the column names
dtHeader = dtTemplate << subset( selectd rows( 0 ), selected columns( 0 ) );
dtHeader << select where( Row() > 0 );
dtHeader << delete rows;
// Change the column data type to match in incoming target data
dtHeader:Column 1 << datatype( character );
// Concatenate the data together. JMP will match all columns with the
// same name, and create new columns for ones that don't have a match
dtInterim = dtHeader << concatenate( dtTarget );
// Loop across the new columns and assign the values back to the columns
// the values need to be in
For( i = N Cols( dtHeader ) + 1, i <= N Cols( dtInterim ), i++,
start = Num( Word( 1, Column( dtInterim, i ) << get name, "+" ) );
end = Num( Word( 2, Column( dtInterim, i ) << get name, "+" ) );
For( k = start, k <= end, k++,
Column( dtInterim, Char( k ) )[1] = Column( dtInterim, i )[1]
);
);
// Delete the extra columns
dtInterim << delete columns( index(N Cols( dtHeader ) + 1, N Cols( dtInterim )));
안녕하세요 안녕하세요. ,
나는 당신이 무엇을 추구했는지 완전히 이해했는지 모르겠지만 그렇게 생각하고 약 하루 동안 작업했습니다. (저는 프로그래머 나 JSL에 능숙하지 않습니다. 헉헉 , 그는 자신의 물건을 알고 있습니다!). 나는 또한 그의 코드를 시도하지 않았지만 그것에 대해 다르게 생각했습니다 (나는 생각합니다).
아래 코드는 "+"가있는 "대상"데이터 테이블에서 열 이름을 가져 와서 해당 특정 열을 함께 추가하는 "템플릿"데이터 테이블에 새 수식 열을 만듭니다. 그런 다음 데이터 테이블의 적절한 위치로 이동하고 함께 추가 된 원래 열을 삭제합니다. 또한 열에서 수식 속성을 제거합니다.
열 이름은 숫자이기 때문에 올바른 방법으로 검색하는 데 하루 정도 걸렸습니다. Eval () 및 Parse () 명령 등없이 문자 이름을 참조하기 위해 문자 이름을 갖는 것이 훨씬 쉽습니다. 누군가 더 우아하게 만들 수 있다고 확신합니다. 수행 방법). 거기에 Wait () 명령을 넣었지만 아마 필요하지 않을 것입니다.
Names Default To Here( 1 );
//defines the two data tables, they must be open already and named appropriately
dt_target = Data Table( "Target" );
dt_template = Data Table( "Template" );
//This gets the column names for each table
target_col_names = dt_target << get columnnames( Numeric, string );
template_col_names = dt_template << get column Names( Numeric, string );
//This tests the column names in the target data table to see if there is a "+" and if so puts that column name in the target_col_keep list
target_col_keep = {};
For( i = 1, i <= N Cols( dt_target ) - 1, i++,
If( Contains( target_col_names[i], "+" ) != 0,
Insert Into( target_col_keep, target_col_names[i] )
)
);
//This loops through the items in target_col_keep to make new columns and add formulas.
//The complicated part of As Column(Num(Word(Eval(EvalExpr(Expr()))))) basically converts the number names to a reference-able column.
//The extra +1 is there because of the first column in the dt_template data table -- it offsets the column numbers on down the line in <BR />//reference to the target data table.
//The first word command gets only the first column of the added up to the "+", hence Word(1,...)
//The second word command gets only the second word after the "+", hence Word(2,...)
//The new columns are added to the end of the data table.
i=.;//reset counter
For( i = 1, i <= N Items( target_col_keep ), i++,
dt_template << New Column( target_col_keep[i],
"Numeric",
"continuous",
Formula(
As Column( (Num( Word( 1, Eval( Eval Expr( Expr( target_col_keep[i] ) ) ), "+" ) ) + 1) ) + As Column(
(Num( Word( 2, Eval( Eval Expr( Expr( target_col_keep[i] ) ) ), "+" ) ) + 1)
)
)
);
//this step moves the newly created column after the second column of the sum. Comment out if you don't want to move them.
prevcol = Num( Word( 1, Eval( Eval Expr( Expr( target_col_keep[i] ) ) ), "+" ) );
dt_template << select Columns( As Column( Eval( Eval Expr( Expr( target_col_keep[i] ) ) ) ) ) <<
Move Selected Columns( After( Column( Parse( ":Name(\!"" || Char( prevcol ) || "\!")" ) ) ) );
);
Wait(0.5);
//This part removes the formula. Comment out if you don't want to remove the formula.
j = .;//reset counter
For( j = 1, j <= N Col( dt_template ), j++,
As Column( j ) << Delete property( "Formula" )
);
//This deletes the old columns that were added together. Comment out if you don't want to delete them.
k=.;//reset counter
For( k = 1, k <= N Items( target_col_keep ), k++,
str1 = Num( Word( 1, Eval( Eval Expr( Expr( target_col_keep[k] ) ) ), "+" ) );
str2 = Num( Word( 2, Eval( Eval Expr( Expr( target_col_keep[k] ) ) ), "+" ) );
dt_template << Delete Columns( Column( Parse( ":Name(\!"" || Char( str1 ) || "\!")" ) ) );
dt_template << Delete Columns( Column( Parse( ":Name(\!"" || Char( str2 ) || "\!")" ) ) );
);도움이 되었기를 바랍니다!,
DS