在現有列中建立並填入基於類別的新列你好,
我正在嘗試建立一個快速查詢,其中使用分類列(test_article)建立一系列僅包含資訊子集的列。 如果腳本按預期工作,表格最終會出現 2 個新列(PBS 與 ...)。
| 測試文章 | 測量 | PBS 對比 709547 | PBS 對比 709139 |
| 公共廣播公司 | 1.23 | 公共廣播公司 | 公共廣播公司 |
| 公共廣播公司 | 1.456 | 公共廣播公司 | 公共廣播公司 |
| 709547 | 4.56 | 709547 | 排除 |
709139 | 5.02 | 排除 | 709139 |
| 709139 | 6.02 | 排除 | 709139 |
| 709547 | 4.57 | 709547 | 排除 |
我嘗試過以下腳本:
NamesDefaultToHere(1);
dt=current data table();
row = Associative Array( :test_article ) << Get Keys;
nc=N items (row);
For( i = 1, i <= nc, i++,
new column("PBS vs "|| row[i],"Character", "Nominal", Formula(If( :test_article == "PBS", :test_article,
If( :test_article == row[i],
"test",
"EXCLUDE"
)
))));不知何故,它不會在新列中填入任何值(“PBS”除外)。
有什麼建議麼?
多謝
賽巴斯蒂安
回覆:在現有列中建立並填入基於類別的新列也像魅力一樣發揮作用。
多謝回覆:在現有列中建立並填入基於類別的新列奇蹟般有效!
謝謝回覆:在現有列中建立並填入基於類別的新列您需要將 row[i] 的值帶入公式中。 JMP 不會計算 New Column() 訊息的 Formula() 部分內的表達式。
您可以使用代替()將 row[i] 的實際值代入公式中。
Names Default To Here( 1 );
dt = Current Data Table();
row = Associative Array( :test_article ) << Get Keys;
nc = N Items( row );
For( i = 1, i <= nc, i++,
Eval(
Substitute(
Expr(
New Column( "PBS vs " || row[i],
"Character",
"Nominal",
Formula( If( :test_article == "PBS" | :test_article == ri, :test_article, "EXCLUDE" ) )
)
),
Expr( ri ), Eval( row[i] )
)
)
);
回覆:在現有列中建立並填入基於類別的新列您遇到的主要問題是,在公式的定義中,不能有需要評估的項目。JMP 認為只有在執行公式時才會評估公式定義中的所有內容。
因此,傳遞到新列定義中的公式的語法必須完整。下面的程式碼修改適用於您的範例資料表。
Names Default To Here( 1 );
dt = Current Data Table();
row = Associative Array( :test_article ) << Get Keys;
nc = N Items( row );
For( i = 1, i <= nc, i++,
Eval(
Parse(
"New Column( \!"PBS vs " || row[i] ||
"\!",
Character,
Nominal,
Formula(
if (Row() == 1, theTest = \!""
|| row[i] ||
"\!");
If( :test_article == \!"PBS\!",
zip=:test_article,
If( :test_article == theTest,
zip=\!"test\!",
zip=\!"EXCLUDE\!"
)
);
zip
)
)
);"
)
)
);
