尋找名稱 jsl 的正確格式你好!
我製作了一個 jsl 腳本,如下所示:
For Each Row(
dt_fichier3,
// Lire la valeur de la colonne "Process" et les offsets
process_value = :Process;
first_offset = :first_OFFSET;
second_offset = :second_OFFSET;
third_offset = :third_OFFSET;
// Vérifier et assigner les valeurs des offsets si elles ne sont pas vides ou "."
If(
(Char(first_offset) != "." & Char(first_offset) != "") | (Char(second_offset) != "." &
Char(second_offset) != "") | (Char(third_offset) != "." & Char(third_offset) != ""),
// Créer une nouvelle colonne dans le fichier1 si elle n'existe pas encore
new_column_name = process_value || "_offset";
dt_fichier1 << New Column(new_column_name, Numeric, Continuous);
// Définir la formule pour la nouvelle colonne
Column(dt_fichier1, new_column_name) << Set Formula(
Eval(
Eval Expr(
If(:Supplier == "FIRST",
:Expr(process_value) + Expr(:first_OFFSET),
If(:Supplier == "SECOND",
:Expr(:Process) + Expr(:second_OFFSET),
If(
:Supplier == "THIRD",
:Expr(:Process) + Expr(:third_OFFSET),
,
:Expr(:Process) // Valeur par défaut si aucun fournisseur ne correspond
)
)
)
)
)
);
);
);
編輯(2024-08-08 jthi):新增了 jsl 格式
問題是公式不起作用,因為列名在列資訊->公式中顯示為“Column_name”,或應該是“Column-name”n,我嘗試使用 Name() 函數,但它不起作用:(
自動化和腳本編寫資料存取數據探索和視覺化回覆:尋找名稱 jsl 的正確格式使用表達式求值建構公式使用 Eval Insert、Eval Expr、Parse 和 Substitute 將一個表達式插入到另一個表達式中。這通常是我的首選方法(或 Eval(Substitute()) 和 NameExpr(AsColumn())
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
col1 = "height";
col2 = "weight";
new_col = Eval(EvalExpr(dt << New Column("mycol", Numeric, Continuous, Formula(
Expr(NameExpr(AsColumn(dt, col1))) * Expr(NameExpr(AsColumn(dt, col2)))
))));
new_col << get formula;回覆:尋找名稱 jsl 的正確格式正確的,
但例如在腳本編譯後,如果我用一列來查看其公式,我會得到以下結果:
If(:供應商==「第一」,
“列名”+ 4,
If(:供應商==「第二」,
“列名”+ 5,
If(:供應商==「第三」,
「列名」+ (-10),
“列_名稱”
)
)
)
這是行不通的,因為它應該像這樣工作:
If(:供應商==「第一」,
“列_姓名”n + 4,
If(:供應商==「第二」,
“列_姓名”n + 5,
If(:供應商==「第三」,
“列名”n + (-10),
“列_名稱”n
)
)
)
那我該如何修改我的腳本呢?謝謝:)
回覆:尋找名稱 jsl 的正確格式您缺少:在您的列中,在原始腳本中您必須至少修改這些:Expr(:Process)。我還建議使用列名而不是引用,例如 process_value = :Process (process_value = "Process" 是我更喜歡使用的)。
回覆:尋找名稱 jsl 的正確格式我不明白你,
如果我使用process_value = "Process" 那麼它將變成一個字串並且不會採用列名。
此外,我需要在這些 :Expr(:Process) 中更改什麼?
回覆:尋找名稱 jsl 的正確格式在我之前的回覆中,我確實展示了一種將這些(字串)轉回公式內的列的技術。
回覆:尋找名稱 jsl 的正確格式啊...在該位置使用 :Process 是正確的,因為您正在使用 For Each Row 迴圈。仍然適用相同的方法將從列中取得的值轉換回列
回覆:尋找名稱 jsl 的正確格式你能把它應用到我的腳本中嗎,我不明白
回覆:尋找名稱 jsl 的正確格式如果您可以提供數據表,我可以提供更好的範例。
回覆:尋找名稱 jsl 的正確格式這是數據
回覆:尋找名稱 jsl 的正確格式我認為這正是您正在尋找的。我使用 Eval(Substitute()) 因為直接從程式碼中讀取它正在做什麼通常更容易一些。我還將求值與表達式建置分開,因此如果您想查看它的樣子,可以列印它。只要您有正確的表作為當前資料表,也可以透過將目前行設定為特定值來偵錯 For Each 迴圈。
Names Default To Here(1);
dt1 = Open("$DOWNLOADS/DATAtable1.jmp");
dt2 = Open("$DOWNLOADS/DATAtable2.jmp");
//Row() = 2;
For Each Row(
dt2,
process_value = :Process;
first_offset = :first_OFFSET;
second_offset = :second_OFFSET;
third_offset = :third_OFFSET;
If(
(Char(first_offset) != "." & Char(first_offset) != "") | (Char(second_offset) != "." &
Char(second_offset) != "") | (Char(third_offset) != "." & Char(third_offset) != ""),
new_column_name = process_value || "_offset";
col_expr = Substitute(
Expr(dt1 << New Column(new_column_name, Numeric, Continuous, Formula(
If(:Supplier == "FIRST",
_processval_ + _firstoffset_
, :Supplier == "SECOND",
_processval_ + _secondtoffset_
, :Supplier == "THIRD",
_processval_ + _thirdoffset_
, // else
_processval_
)
))),
Expr(_processval_), Name Expr(AsColumn(dt1, process_value)),
Expr(_firstoffset_), first_offset,
Expr(_secondtoffset_), second_offset,
Expr(_thirdoffset_), third_offset
);
//show(col_expr);
new_col = Eval(col_expr);
);
);
