按名稱關聯列我有事要在這裡做
已解決:自動繪製關聯列 - JMP 使用者社群
但我確信這很麻煩。我有以字母 H(高)結尾的列名,我需要將其與其他匹配但以字母 L(低)結尾的列名關聯起來。我可以建立一個關聯數組,其中的列名最後一個字元被刪除。不知道下一步該做什麼?
names default to here(1);
dt = Current Data Table();
colList = dt << get column names( string );
for each({col,index}, colList,
//colList[index] = substr(col,1,3)
colList[index] = Left(col,Length(col)-1)
);
grps = associative array(colList)<<GET keys=""></GET>
<P>例如,VT123ABCH 需要針對 VT123ABCL 進行繪圖等等。</P><LINGO-LABS id="lingo-labs-848773" slang="en-US" mode="CREATE"><LINGO-LABEL>自動化和腳本</LINGO-LABEL></LINGO-LABS>回覆:按名稱關聯列這些對總是存在嗎?表中除了這些對以外還有其他欄位嗎?它們的順序是特定的嗎?
編輯:
根據實際使用情況,很有可能會做得更好
names default to here(1);
dt = New Table("",
New Column("VT123ABCH"),
New Column("VT123ABCL")
);
collist = dt << get column names(string);
hcols = Filter Each({colname}, colList,
Ends With(colname, "H");
);
aa = Associative Array();
For Each({hcolname}, hcols,
lcolname = Left(hcolname, Length(hcolname) - 1) || "L";
If(dt << Has Column(lcolname),
aa[hcolname] = lcolname
);
);
Show(aa);回覆:按名稱關聯列這是一個你可以做你想做的事情的例子

Names Default To Here( 1 );
dt =
// Open Data Table: semiconductor capability.jmp
// → Data Table( "semiconductor capability" )
Open( "$SAMPLE_DATA/semiconductor capability.jmp" );
colNames = dt << get column names( continuous, string );
For Each( {col}, colNames,
If( Ends With( col, "1" ) & Contains( colNames, Substr( col, 1, Length( col ) - 1 ) || "2" ),
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Variables( X( As Column( col ) ), Y( As Column( Substr( col, 1, Length( col ) - 1 ) || "2" ) ) ),
Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);
)
);回覆:按名稱關聯列賈爾莫
看起來比我有的整潔得多,但是,我收到了這個錯誤。
“物件‘資料表’無法辨識訊息‘有列’”
回覆:按名稱關聯列這是在 JMP18 中添加的

您可以將其更改為 Contains(),大多數情況下應該沒問題
Contains(collist, lcolname)
回覆:按名稱關聯列賈爾莫
這很接近,但我注意到 hcolname 是空的,而 lcolname 有一個值。我是否需要將 hcolname 建立為物件或清單?
回覆:按名稱關聯列hcols 應該包含以「H」結尾的所有欄位的清單。然後在 For Each 中使用它,如果項目將逐一用作 hcolname。您可以添加調試打印來了解發生了什麼。而且,這絕對不是實現這一目標的唯一方法,例如,您可以在一個循環中輕鬆實現。
回覆:按名稱關聯列
賈爾莫
這讓我更接近一點,但 lcolname 直到最終值才填入。
For Each({hcolname, index}, hcols,
{lcolname, index}, hcols = Left(hcolname, Length(hcolname) - 1) || "L";
If(dt << Contains(collist, lcolname),
aa[hcolname] = lcolname
);
);回覆:按名稱關聯列對我來說它似乎運作良好。您可以將範例表更改為半導體能力,並在末尾檢查一些數字
Names default to here(1);
dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
collist = dt << get column names(string);
hcols = Filter Each({colname}, colList,
Ends With(colname, "1");
);
aa = Associative Array();
For Each({hcolname}, hcols,
lcolname = Left(hcolname, Length(hcolname) - 1) || "2";
If(dt << Has Column(lcolname),
aa[hcolname] = lcolname
);
);
Show(aa);
aa = ["ESM1" => "ESM2", "FST1" => "FST2", "INM1" => "INM2", "IVP1" => "IVP2", "NPN1" => "NPN2", "PBA1" => "PBA2", "PLG1" => "PLG2", "PLY1" => "PLY2", "PNP1" => "PNP2", "RES1" => "RES2", "RSP1" => "RSP2", "SIT1" => "SIT2", "VDP1" => "VDP2", "VPM1" => "VPM2"];
但你也可以選擇稍微不同的路線,增加一些設定選項
Names Default To Here(1);
endchar1 = "1";
endchar2 = "2";
rgx_endchar1 = Eval Insert("(.+?)^endchar1^$");
dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
collist = dt << get column names(string);
aa = Associative Array();
For Each({colname}, collist,
col_ptrn = Regex(colname, rgx_endchar1, "\1");
If(!IsMissing(col_ptrn), // ends with H
If(Contains(collist, col_ptrn || endchar2),
aa[col_ptrn || endchar1] = col_ptrn || endchar2;
);
);
);
show(aa);
對我來說,這兩個都回傳了相同的結果
回覆:按名稱關聯列吉姆
很棒的腳本,而且簡單得多。我做了一些調整,將所有的圖都放在一個「編譯」視窗中。
Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << get column names( continuous, string );
New Window( "Compilation",
For Each( {col}, colNames,
If(
Starts With( col, "VT" ) & Contains(
colNames,
Substr( col, 1, Length( col ) - 1 ) || "H"
),
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Variables(
X( As Column( col ) ),
Y( As Column( Substr( col, 1, Length( col ) - 1 ) || "L" ) )
),
Wrap( :LOT ),
Elements(
Points( X, Y, Legend( 1 ) ),
Line Of Fit( X, Y, Legend( 3 ) )
)
)
)
)
);回覆:按名稱關聯列賈爾莫
JMP 的奇怪之處。第一個不起作用,第二個起作用,JMP 17 可能嗎?謝謝你的包容。