次の例のように、式 B2/A2、C2/A2 でシリーズの新しい列を追加したい
実装方法
ありがとう

colname = dt << get column names( string, continuous );
nc = N Items( colname );
For( p = 1, p < nc, p++,
For( i = 1, i < nc, i++,
a = "Bin" || Char( p );
b = Char( a ) || Char( "(%)" );
If( Contains( colname[i], a ),
dt << New Column( b, formula( :colname[i] / :name( "Total" ) ) )
);
)
);
列名に特殊文字が含まれている場合は、置換で Parse( "As Column \!"" || colname[i] || "\!"" ) を使用できます。元の投稿では Name() を使用しようとしましたが、これは引用符で囲まれた文字列しか受け入れないため、スクリプトで使用するのは困難です。
良い。 ラストの表情操作とキャラ操作のミックス&マッチが好き!
1 Eval(
2 Substitute(
3 Expr(
4 dt << New Column( colname[i] || "%",format("Percent",7,2),
5 formula( __col__ / :name( "Total" ) ) )
6 ),
7 Expr( __col__ ),
8 Parse( ":" || colname[i] )
9 )
10 )</CODE>4 行目と 5 行目は、式として操作される JSL です。 __col__ はプレースホルダーです。</P><P>3行目と6行目は<EM>引用</EM>式を実行しないようにします。</P><P>行 7 は、置き換えられるビットを識別します。<EM>引用した</EM>したがって、実行されません。</P><P>行 8 は置換値です。 これは、2 つの文字列の連結として JSL を実際に構築し、それを構文解析して式にするため、興味深いものです。 parse 関数の結果は式です。</P><P>2 行目と 9 行目は、<EM> Substitute(ソース、パターン、置換)</EM>関数。 3 つの式引数から構築された式を返します。</P><P>1 行目と 10 行目で式を評価します。</P></LINGO-BODY><LINGO-SUB id="lingo-sub-284389" slang="en-US">Re: for ループで行に新しい列を追加する方法</LINGO-SUB><LINGO-BODY id="lingo-body-284389" slang="en-US"><P>問題を必要以上に複雑にしていました。以下は、少し注釈を付けたコードのリワークです</P>
<PRE><CODE class=" language-jsl">Names Default To Here( 1 ); // This line tells JMP to isolate the variable used to this script
// Set a variable to point to the current active data table
dt = Current Data Table();
// Get the column names
colname = dt << get column names( string, continuous );
// Determine the number of columns to loop through
nc = N Items( colname );
// Loop across all of the columns in the colname list
// Your original code was For( i = 1, i < nc, i++,
// with "i < nc" the last colname would not be processed
For( i = 1, i <= nc, i++,
// If this is a column name that starts with "Bin"
// a new % column needs to be added
If( Left( colname[i], 3 ) == "Bin",
// Create the new column
Eval(
Substitute(
Expr(
dt << New Column( colname[i] || "%",format("Percent",7,2),
formula( __col__ / :name( "Total" ) ) )
),
Expr( __col__ ), Parse( ":" || colname[i] )
)
)
)
);