特定の値を持つ列名を取得するやあ、
仕事で jmp を使い始めて、JSL を学ぼうとしています。 行値 = 1 の列名を取得するスクリプトを作成しようとしています。 たとえば、テーブルにはさまざまな IMCX 列の下に 0 と 1 の値が表示されており、各行でどの列の値が =1 であるかを調べて、IMC という新しい列の下に保存したいとします。 最初の行の列 IMC 4 には 1 があるため、IMC の下に IMC4 を手動で入力します。 テーブルには 5000 行を超える行があります。 お手伝いありがとう。

自動化とスクリプト作成Re: 特定の値を持つ列名を取得するこんにちは、イアンさん
時間をかけてヘルプ>書籍セクションを読み、キーワードを 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: 特定の値を持つ列名を取得するこんにちはイアン、お時間を割いてご説明いただきありがとうございます。 コードは理解できます。 ただし、dt を現在のテーブルとして設定してスクリプトを実行すると、結果の式列に empty() が表示されました。 ここで学ぶには長い道のりがあります。 ご意見やご提案をいただきありがとうございましたRe: 特定の値を持つ列名を取得するお時間を割いていただき、ありがとうございました。 問題を明確に述べていなかったことをお詫びします。 各行では、列の下に 1 のインスタンスが 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以下の 2 つの理由により提案されました。
- JMP から直接見つかった非常に多くのメニュー項目を使用しているため、ほとんどJSL の知識がなくても、データテーブルのソースからコピー&ペーストするだけでスクリプトを作成できます。
- すべてにおいて非常にJSLのような構文を使用しています。 << 場所を選択など
- (このソリューションで示されているワークフローは非常に JMP に似ていると思います)
Re: 特定の値を持つ列名を取得する最初の入力を読んだところ、特定の行の複数の列の値が 1 である可能性があると考えられます。そうでない場合、次の 2 つのスクリプトは使用する方法ではありません。
これを行うための 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( [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 );

これを行う 2 番目の方法は次のとおりです。 この例では、特定の行の複数の列の値が 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: 特定の値を持つ列名を取得するこんにちは。
データがこの例のようで、すべての列が数値 (連続データ) であり、> 3000 などの切り捨てられた列名を選択したい場合 (1 行に 3000 を超える列が複数ある可能性があります)、スクリプトでは何をすればよいですか?
私は次のスクリプトを使用します
colNames = dt <<列名を取得( "String" );
( i = N 項目(colNames)、i > 3000 、i--、
);
しかしそれは機能しませんでした。
最高