특정 값을 가진 열 이름 가져오기안녕,
직장에서 jmp를 사용하기 시작했고 JSL을 배우려고 했습니다. 행 값이 1인 열 이름을 가져오는 스크립트를 작성하려고 합니다. 예를 들어 테이블은 서로 다른 IMCX 열 아래에 0과 1의 값을 표시하고 각 행에서 값이 1인 열을 찾아 IMC라는 새 열 아래에 저장하려고 합니다. 첫 번째 행에서 열 IMC 4에는 1이 있으므로 IMC 아래에 수동으로 IMC4를 입력합니다. 테이블에는 5000개가 넘는 행이 있습니다. 도와 주셔서 감사합니다.

자동화 및 스크립팅Re: 특정 값을 가진 열 이름 가져오기안녕 이안,
help>Books 섹션을 읽는 데 시간을 할애하고 키워드를 loc에서 contains로 변경했습니다. 고마워요!
// Get a list of the column names
colList = dt << getColumnNames( "String" );
// Get the '0's and '1's into a matrix
mat = dt << getAsMatrix;
// Value to search for
searchVal = 1;
// Add an 'expression' column and loop rowise . . .
newCol = dt << New Column( "Value " || Char( searchVal ) || " found in Column:", Expression );
for( r = 1, r <= N Row( dt ), r++,
newCol[r] = colList[Contains( mat[r, 0], searchVal )]
);Re: 특정 값을 가진 열 이름 가져오기시간을 내어 도와주셔서 감사합니다. 스크립트를 성공적으로 실행할 수 없었습니다. 열 IMC를 만들었지만 그 안에 값이 없습니다. 디버깅하고 코드를 더 잘 이해하려고 노력할 것입니다.Re: 특정 값을 가진 열 이름 가져오기안녕 Ian, 당신의 시간과 설명에 감사드립니다. 나는 당신의 코드를 이해할 수 있습니다. 그러나 dt를 현재 테이블로 설정하는 스크립트를 실행했을 때 결과 표현식 열에 empty()가 표시되었습니다. 나는 여기서 배울 길이 멀다. 귀하의 의견과 제안에 감사드립니다.Re: 특정 값을 가진 열 이름 가져오기시간을 내어 도와주셔서 감사합니다. 문제를 명확하게 설명하지 못한 점 죄송합니다. 각 행에는 열 아래에 1의 인스턴스가 하나만 있고 열 이름을 선택하고 새 열 아래에 저장해야 합니다.Re: 특정 값을 가진 열 이름 가져오기매우 감사합니다. 그것은 효과가 있었다!Re: 특정 값을 가진 열 이름 가져오기에 관하여 " 직장에서 jmp를 사용하기 시작했고 JSL을 배우려고 합니다. "(이미 암시된 바와 같이) 작업을 완료하는 방법에는 여러 가지가 있습니다.
따라서 이러한 정신에서 또 다른 약간의 변형을 찾으십시오. 작동 방식을 알아보려면 '도움말 > 책 > 스크립팅 가이드'를 사용하십시오.
Names Default To Here( 1 );
// Create a sample data table
dt = New Table( "Example",
Add Rows( 2 ),
New Column( "IMCO", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 0] ) ),
New Column( "IIMC2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1] ) ),
New Column( "IMC4", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 0] ) ),
New Column( "IMC5", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC6", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1] ), Set Display Width( 46 ) ),
New Column( "IMC7", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC8", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC9", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC10", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC11", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
);
// Get a list of the column names
colList = dt << getColumnNames("String");
// Get the '0's and '1's into a matrix
mat = dt << getAsMatrix;
// Value to search for
searchVal = 1;
// Add an 'expression' column and loop rowise . . .
newCol = dt << NewColumn("Value "||Char(searchVal)||" found in Column:", Expression);
for (r=1, r<=NRow(dt), r++,
newCol[r] = colList[Loc(mat[r, 0], searchVal)];
);
Re: 특정 값을 가진 열 이름 가져오기내 솔루션(txnelson과 동일한 샘플 데이터 테이블 사용):
Names Default To Here( 1 );
// Create a sample data table
dt = New Table( "Example",
Add Rows( 2 ),
New Column( "IMCO", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IIMC2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC4", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 0] ) ),
New Column( "IMC5", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC6", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1] ), Set Display Width( 46 ) ),
New Column( "IMC7", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC8", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC9", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC10", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC11", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "RESIDUAL", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [32.3201037, 20.54947] ) ),
New Column( "TEST", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., .] ) )
);
//get wanted columns. Assumes that IMC columns start from column 1 and all IMC columns are one after another
colNames = dt << Get Column Names("String");
For(i = N Items(colNames), i > 0 , i--,
If(!Starts With(colNames[i], "IMC"),
Remove From(colNames, i),
break(); //we can break on first occurance
);
);
//new column with IMC with value 1
dt << New Column("IMC", Character,
<< Set Each Value(
rowValues = dt[Row(), 0][1::N Items(colNames)]; //get values of row as matrix
colIndex = Contains(rowValues, 1); //get index of
If(colIndex > 0, //handle
colNames[colIndex], //get column name with the index
""; //when no 1 found use ""
);
);
);나는 첫 번째 솔루션을 좋아한다 @txnelson 두 가지(세 가지) 이유로 제공됩니다.
- JMP에서 직접 찾은 많은 메뉴 항목을 사용하고 있으므로 거의 데이터 테이블 소스에서 복사-붙여넣기로 JSL 지식 없이 스크립트 작성
- 그것은 매우 JSL과 같은 구문을 사용하고 있습니다. << 위치 선택 그런
- (솔루션에 제시된 그런 종류의 워크플로우는 매우 JMP와 비슷하다고 생각합니다.)
Re: 특정 값을 가진 열 이름 가져오기초기 입력에 대한 나의 읽기는 주어진 행에 있는 하나 이상의 열이 1의 값을 가질 수 있다는 것입니다. 그렇지 않은 경우 다음 2개의 스크립트는 사용할 방법이 아닙니다.
이를 수행하는 한 가지 방법이 있습니다.
Names Default To Here( 1 );
// Create a sample data table
dt = New Table( "Example",
Add Rows( 2 ),
New Column( "IMCO", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IIMC2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC4", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 0] ) ),
New Column( "IMC5", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC6", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1] ), Set Display Width( 46 ) ),
New Column( "IMC7", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC8", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC9", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC10", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC11", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "RESIDUAL", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [32.3201037, 20.54947] ) ),
New Column( "TEST", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., .] ) )
);
// Generate a list of columns to be processed
colNamesList = dt << get column names(string);
remove from (colNamesList,13,2);
// Find the maximum( the ones ) for the columns in question
dtSum = dt<< Summary(
Max(colNamesList),
Freq( "None" ),
Weight( "None" ),
statistics column name format( "column" ),
Link to original data table( 0 )
);
// Stack all of the summarized columns
dtStack = dtSum << Stack(
columns(
colNamesList
),
Source Label Column( "IMC" ),
Stacked Data Column( "Data" )
);
close( dtSum, nosave );
// Delete all data that do not have 1
dtStack << select where(:Data !=1 );
dtStack << delete rows;
// Delete the unwanted columns from the summary table
dtStack << delete columns( {N Rows, data} );
// If there are more rows than in the original table, add rows
if( n rows( dt ) < N Rows( dtStack ),
dt << add rows( N Rows( dtStack ) - N Rows( dt ) )
);
// Add the column names for the columns found with 1's in their data
dt << Update( With( dtStack ) );
close( dtStack, nosave );

두 번째 방법은 다음과 같습니다. 이 예에서 주어진 행에 있는 둘 이상의 열의 값은 1입니다.
Names Default To Here( 1 );
// Create a sample data table
dt = New Table( "Example",
Add Rows( 2 ),
New Column( "IMCO", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 0] ) ),
New Column( "IIMC2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1] ) ),
New Column( "IMC4", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 0] ) ),
New Column( "IMC5", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC6", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1] ), Set Display Width( 46 ) ),
New Column( "IMC7", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC8", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC9", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC10", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "IMC11", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 0] ) ),
New Column( "RESIDUAL", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [32.3201037, 20.54947] ) ),
New Column( "TEST", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., .] ) ),
New Column( "IMC", Character, "Nominal", Set Values( {"IMC1", "IMC3"} ) )
);
// Generate a list of columns to be processed
colNamesList = dt << get column names( string );
Remove From( colNamesList, 13, 2 );
foundNamesList = {};
For( i = 1, i <= N Items( colNamesList ), i++,
theRows = dt << get rows where( As Column( colNamesList[i] ) == 1 );
If( N Rows( theRows ) > 0,
Insert Into( foundNamesList, colNamesList[i] )
);
);
dt << New Column( "IMC", character );
// If there are more rows than in the original table, add rows
If( N Rows( dt ) < N Items( foundNamesList ),
dt << add rows( N Items( foundNamesList ) - N Rows( dt ) )
);
If( N Items( foundNamesList ) > 0,
dt:IMC << set values( foundNamesList )
);

Re: 특정 값을 가진 열 이름 가져오기다음과 같이 할 수 있습니다.

결과 열의 수식은 다음과 같습니다.
If( :A == 0,
"",
Char( Column Name( 1 ) )
) || If( :B == 0,
"",
Char( Column Name( 2 ) )
) || If( :C == 0,
"",
Char( Column Name( 3 ) )
) || If(
== 0,
"",
Char( Column Name( 4 ) )
)
나는 사용한다 사슬 같이 잇다 각 열이 1인지 확인하는 키워드입니다.
그것이 당신에게 효과가 있는지 알려주세요!
Re: 특정 값을 가진 열 이름을 가져옵니다.안녕하세요 jthi 님,
내 데이터가 이 예와 비슷하지만 모든 열이 숫자(연속 데이터)이고 > 3000(한 행에 3000보다 큰 열이 여러 개 있을 수 있음)과 같이 잘린 열 이름을 선택하려는 경우 스크립트에서 어떻게 해야 합니까? ?
나는 다음 스크립트를 사용합니다
colNames = dt << 열 이름 가져오기 ( "String" );
( i = N 항목 (colNames), i > 3000 , i--,
);
하지만 작동하지 않았습니다.
최상의