按名称关联列我有事要在这里做
已解决:自动绘制关联列 - 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,则将其用作 each。您可以添加调试打印以了解发生了什么。此外,这绝对不是执行此操作的唯一方法,例如,您可以在单个循环中轻松执行此操作。
回复:按名称关联列
贾尔莫
这让我更接近一点,但 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 起作用?谢谢你的包容。