아래 예와 같이 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행은 대체 값입니다. 이것은 실제로 두 문자열의 연결로 일부 JSL을 빌드한 다음 이를 표현식으로 구문 분석하기 때문에 흥미롭습니다. 구문 분석 함수의 결과는 표현식입니다.</P><P>2행과 9행은<EM> 대체(소스, 패턴, 교체)</EM> 기능. 세 개의 표현식 인수로 작성된 표현식을 리턴합니다.</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] )
)
)
)
);