Ich möchte eine neue Spalte mit einer Formel B2 / A2, C2 / A2 hinzufügen ... wie im folgenden Beispiel
wie ich es umsetze
Vielen Dank

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" ) ) )
);
)
);
Falls der Spaltenname Sonderzeichen enthält, können Sie Parse( "As Column \!"" || colname[i] || "\!"" ) in der Substitution verwenden.Der ursprüngliche Beitrag hat versucht, Name() zu verwenden, was in Skripten schwer zu verwenden ist, da es nur eine Zeichenfolge in Anführungszeichen akzeptiert.
Nett. Ich mag das Mix'n'Match von Ausdrucksmanipulation und Charaktermanipulation am Ende!
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>Die Zeilen 4 und 5 sind die JSL, die als Ausdruck manipuliert wird; das __col__ ist ein Platzhalter.</P><P>Die Zeilen 3 und 6 sind<EM> zitieren</EM> den Ausdruck, damit er nicht versucht zu laufen.</P><P>Zeile 7 identifiziert auch das zu ersetzende Bit<EM> zitiert</EM> also wird es nicht ausgeführt.</P><P>Zeile 8 ist der Wiederbeschaffungswert. Das ist interessant, weil es tatsächlich etwas JSL als Verkettung von zwei Strings erstellt und es dann in einen Ausdruck parst. Das Ergebnis der Parse-Funktion ist ein Ausdruck.</P><P>Die Zeilen 2 und 9 sind die<EM> Ersatz (Quelle, Muster, Ersatz)</EM> Funktion. Es gibt einen Ausdruck zurück, der aus den drei Ausdrucksargumenten erstellt wurde.</P><P>Die Zeilen 1 und 10 werten den Ausdruck aus.</P></LINGO-BODY><LINGO-SUB id="lingo-sub-284389" slang="en-US">Betreff: wie man eine neue Spalte in einer Zeile mit einer for-Schleife hinzufügt</LINGO-SUB><LINGO-BODY id="lingo-body-284389" slang="en-US"><P>Sie haben das Thema komplexer gemacht, als es sein muss.Unten ist eine Überarbeitung Ihres Codes mit ein wenig Anmerkung</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] )
)
)
)
);