你好,
JMP 新手,已经搜索并阅读了大量帮助并兜圈子。 我认为我所做的事情是简单直接的,但 JSL 却没有这种感觉。 我有一个更复杂的数据表,但为了让我的代码正常工作,我简化了我的表。 我有一个包含 5 列的表格,其中 4 列的标题中包含“_Yield”。 13 行由 1 和 0 组成,我想要做的是为每一行创建一个列,显示产量列中第一次出现的 1。 我需要它是智能的,因为列名称(包含 _yield 除外)并不总是具有相同的名称或位于相同的位置。 我已经弄清楚如何查看产量列并将其转换为矩阵,然后我可以在其中找到我正在寻找的值。 我只是无法将这些值转换为列标题。 测试列显示矩阵中的位置,下面的结果列显示我应该在帮助列中获得的内容。提前致谢。

dt = Current Data Table();
lst = dt << Get Column Names(string);
dt << clear column selection;
For(i = 1, i <= N Items(lst), i++,
If(Contains(lst[i], "_Yield") > 0,
Column(dt, lst[i]) << set selected;
selcols = dt << get selected columns;
)
);
Mat2 = dt << Get as Matrix(selcols);
DesList = List();
For(i = 1, i <= N Rows(Mat2), i++,
Pos = Min(Loc(Mat2[i, 0]));
Insert Into(DesList, Pos);
);
dt << New Column("Test", Numeric, Continuous, <<SET values="">= 1);
If(
result >= 1, (newcolumn[j] = selcols),
Is Missing(result), (newColumn[j] = Parse("PASS"))
);
);</SET>嗨,jthi,
感谢您的回复。 Filter Each 对我来说不是一个活跃的功能。 也许是因为我使用的是 V15,但我能够使用当前的方式通过您的 one_idx 方程选择列名称,并且它很有效。 上周我一直在努力使用 Loc 函数,所以这确实很有帮助。
一个例子:
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(3),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 1, 0])),
New Column("A_YIELD", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 1, 0])),
New Column("B_YIELD", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0, 0])),
New Column("C_YIELD", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 1, 0]))
);
// Get column names which end in _YIELD
yield_cols = Filter Each({col_name}, dt << Get Column Names("Continuous", "String"),
Ends With(col_name, "_YIELD");
);
// create new column to get _YIELD column name
dt << New Column("RESULT", Character, Nominal, << Set Each Value(
one_idx = Loc(dt[Row(), yield_cols], 1);
If(N Items(one_idx),
yield_cols[Min(one_idx)];
,
"PASS"
);
));
