跨多列的每一行的最大值和源列的对应名称嗨,有没有一种简单的方法可以找到每行的最大值以及对应于最大值的列名(或参数)? 下面是一个简单的例子来说明请求:
| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10 | 最大值 | Col_Name(参数) |
| 87.2 | 83.6 | 81.4 | 83 | 83 | 83 | 83 | 82.3 | 83.3 | 84.6 | 87.2 | T1 |
| 85.9 | 84 | 82 | 84 | 83.3 | 83.3 | 84 | 83 | 86.5 | 87.2 | 87.2 | T10 |
| 84.9 | 82.7 | 86 | 83 | 82.3 | 82.3 | 83 | 82 | 83.6 | 85.2 | 86 | T3 |
| 85.6 | 84.6 | 82.7 | 84.6 | 84.3 | 84.3 | 84.3 | 83.6 | 84.9 | 86.2 | 86.2 | T10 |
| 85.2 | 83.6 | 82 | 83.3 | 83 | 83 | 83.3 | 82.3 | 84.3 | 85.6 | 85.6 | T10 |
| 86.8 | 84.3 | 82.7 | 84.3 | 83.6 | 83.6 | 84.3 | 83.3 | 85.9 | 86.2 | 86.8 | T1 |
| 86.2 | 84 | 82.3 | 84 | 87 | 83.3 | 83.6 | 83 | 84.9 | 85.9 | 87 | T5 |
| 88.1 | 84.6 | 82.3 | 84.3 | 83.6 | 84 | 84.3 | 83.3 | 85.9 | 86.2 | 88.1 | T1 |
| 85.6 | 83.3 | 81.7 | 83.3 | 83 | 83 | 83.6 | 82.7 | 84 | 85.9 | 85.9 | T10 |
| 37.4 | 36.1 | 36.4 | 36.4 | 36.1 | 36.1 | 36.4 | 35.4 | 36.7 | 37.4 | 37.4 | T1 |
| 36.7 | 34.5 | 34.8 | 34.5 | 33.8 | 34.1 | 34.5 | 33.5 | 36.1 | 36.1 | 36.7 | T1 |
| 34.8 | 32.9 | 33.2 | 32.9 | 32.2 | 32.5 | 36 | 31.9 | 33.8 | 35.1 | 36 | T7 |
| 38 | 36.4 | 36.4 | 36.4 | 36.4 | 36.1 | 36.7 | 39 | 38 | 38.3 | 39 | T8 |
| 38 | 35.1 | 35.1 | 40 | 34.1 | 34.5 | 34.8 | 33.8 | 36.4 | 37 | 40 | T4 |
谢谢!
Re: 跨多列的每一行的最大值和源列的对应名称一开始我误读了你的问题......所以这个答案包含一个简化,不使用substituteInto,以及一个寻找特定值的变体。
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "first", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 5, 9] ) ),
New Column( "second", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 6, 10] ) ),
New Column( "skip", character, setvalues( {"a", "b", "c"} ) ),
New Column( "third", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 7, 11] ) ),
New Column( "fourth", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 8, 12] ) )
);
names = dt << getcolumnnames( "numeric" ); // returns a list of all numeric column names
findval=7;
row = 2;
Row() = row; // names will pull data from the current row
rowpos = Loc( findval==matrix(evallist(names)) );
show(names[rowpos],names[rowpos[1]][row]);
names[rowpos] = {:third};
names[rowpos[1]][2] = 7;
Loc 返回矩阵中非零项的位置。 带有标量和矩阵的 == 运算符返回一个由 1 和 0 组成的矩阵。 Loc 函数返回 rowpos 中的矩阵(带有 1 的索引); [1] 采用与 findval 匹配的第一个位置。 names[rowpos[1]] 然后是列名,[row] 从列的行中获取匹配的答案。
Re: 跨多列的每一行的最大值和源列的对应名称谢谢克雷格!
除了 Concat(),还有任何其他函数可以与 Substitute Into() 一起使用,以在多列的行中查找特定值的位置?
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "first", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 5, 9] ) ),
New Column( "second", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 6, 10] ) ),
New Column( "skip", character, setvalues( {"a", "b", "c"} ) ),
New Column( "third", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 7, 11] ) ),
New Column( "fourth", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 8, 12] ) )
);
names = dt << getcolumnnames( "numeric" ); // returns a list of all numeric column names
Show( names ); // {first, second, third, fourth}
Substitute Into( names, Expr( {} ), Expr( Concat() ) );
Show( Name Expr( names ) ); // first || second || third || fourth
Row() = 2; // names will pull data from the current row
rowpos = Loc( names, 6 ); // works only with a list
谢谢,
拉维
Re: 跨多列的每一行的最大值和源列的对应名称(查找 IFMax ...)是的,如果您可以轻松列出列,那将更容易解释。 也可能更快。 感谢您指出!
Re: 跨多列的每一行的最大值和源列的对应名称在新列中使用 IFMax 函数有什么问题吗?我意识到如果列数很大,这很笨拙,但是如果只有 20 列或更少,则只需输入 IFMax 公式就很简单了。
Re: 跨多列的每一行的最大值和源列的对应名称数据表下标是 JMP 13 中的新增功能。
您可以尝试类似这个想法来构建一个表达式,该表达式将在评估时从当前行创建一个行向量矩阵。
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "first", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 5, 9] ) ),
New Column( "second", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 6, 10] ) ),
New Column( "skip", character, setvalues( {"a", "b", "c"} ) ),
New Column( "third", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 7, 11] ) ),
New Column( "fourth", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 8, 12] ) )
);
names = dt << getcolumnnames( "numeric" ); // returns a list of all numeric column names
Show( names ); // {first, second, third, fourth}
Substitute Into( names, Expr( {} ), Expr( Concat() ) );
Show( Name Expr( names ) ); // first || second || third || fourth
Row() = 2; // names will pull data from the current row
rowvec = (Eval( names )); // [5 6 7 8]
给定一个行名列表,Substitute Into() 函数将大括号列表运算符替换为 concat 函数。 concat 函数与 || 相同连接运算符,可以接受很多参数。 连接评估当前行列表中的每个列引用。 各个标量值连接到行矩阵中。
Re: 跨多列的每一行的最大值和源列的对应名称嗨克雷格,
当我在 JMP 10 中运行您的示例脚本时,我收到一条错误消息,指出 - 在访问或评估 'Loc Max' 时,参数应该是矩阵{1},错误参数......
JMP10中不允许数据表索引吗?
谢谢!
Re: 跨多列的每一行的最大值和源列的对应名称好的,我遗漏了一些东西......附上我的输出。 当我检查结果时,MaxVal 列包含在该行第 3-25 列中找到的最大值,MaxVal_Col 是找到最大值的列的名称。
我错过了什么?
Re: 跨多列的每一行的最大值和源列的对应名称再次感谢吉姆! 但是,如果您检查输出,我想您会注意到它不正确。
Re: 跨多列的每一行的最大值和源列的对应名称好的....我的错误,我认为您无法运行代码,而不是您得到无效的结果。 问题是您的列列表“colnames”与您正在执行 Loc Max 的列列表不匹配。 第一和第二列名称需要从“colnames”列表中删除。 该问题还导致使用以下语句获取 MaxVal 时出现问题:
MaxVal = dt[r, 位置];
因为它将查看整个数据表,并且它返回的位置基于一个矩阵,该矩阵的列比数据表少 2 列。
所以我做了一个简单的重写,展示了解决这个问题的一种方法
dt = Open( "C:/data.jmp" );
colnames = dt << getcolumnnames;
For( i = 2, i >= 0, i--,
colnames = Remove( colnames, i, 1 )
);
For Each Row(
r = Row();
location = Loc Max( dt[r, 3 :: 25] ); // location of maximum value in array from Col #3 to #25
//MaxVal = dt[r, location];
MaxVal_Col = colnames[location] << getname;
MaxVal = as column(eval(MaxVal_Col));
);
Re: 跨多列的每一行的最大值和源列的对应名称谢谢吉姆! 这就是我得到的结果,输出不正确,例如,第 1 行和第 2 行。
Re: 跨多列的每一行的最大值和源列的对应名称谢谢吉姆! 这就是我得到的结果,输出不正确,例如,第 1 行和第 2 行。
Re: 跨多列的每一行的最大值和源列的对应名称我看到了一些由于缓存而引起的可疑错误。 我解决这些问题的唯一方法是重新启动我的操作系统而不是 JMP 本身。
您能否运行更新的脚本,但在重新启动操作系统并检查后?
Re: 跨多列的每一行的最大值和源列的对应名称这是我运行脚本后的数据表
Re: 跨多列的每一行的最大值和源列的对应名称非常感谢吉姆的回复! 但是,它仍然对我不起作用dt=当前数据表()。 不知道发生了什么。 顺便说一句,你能把你生成的输出文件发给我吗?
谢谢!
Re: 跨多列的每一行的最大值和源列的对应名称脚本和数据表对我来说非常有用。现在,我确实改变了
dt=Open("........");
至
dt=current data table();
因为桌子已经打开了。
因此,我建议您尝试一下,或者在 dt=Open 语句之后添加一条附加语句:
wait(0);
在 For Each Row 开始之前,您的数据表可能尚未完成。等待(0);将在运行 For Each Row 之前强制打开完成
Re: 跨多列的每一行的最大值和源列的对应名称它对我来说仍然无法正常工作。 附件请找到脚本和数据文件。 你能告诉我我在这里做错了什么吗?
谢谢!
Re: 跨多列的每一行的最大值和源列的对应名称好点子。 该示例可以这样概括(故意丑陋的列排列......) 选择最适合您的非此即彼的一个。 第二个的优点是将您与意外的列重新排列隔离开来。 第一个可能适用于 100 列。
dt = New Table( "Untitled",
New Column( "maxval", numeric ),
New Column( "a", Numeric, Set Values( [1, 33, 1] ) ),
New Column( "maxcol", Numeric ),
New Column( "b", Numeric, Set Values( [2, 2, 2] ) ),
New Column( "c", Numeric, Set Values( [333, 1, 0] ) ),
);
// either
vars = [2 4 5];
colnames = (dt << getcolumnnames)[vars];
// or
colnames={a,b,c}; // this might be best choice
For Each Row(
row = Row();
location = Loc Max( dt[ row, colnames] ); // location of maximum value in array
col = colnames[location]<<GETNAME></GETNAME>Re: 跨多列的每一行的最大值和源列的对应名称解决了我缺少必须添加到位置变量的列的偏移量。
Re: 跨多列的每一行的最大值和源列的对应名称我在这里遇到了一个问题,如果我需要选择的列在数据集之间,它似乎不起作用。
For Each Row(
r = Row();
// 1::3 means columns 1 through 3. {a,b,c} would also work.
location = Loc Max( dt[ r, 57 :: 113] ); // location of maximum value in array
maxval = dt[r, location];
maxcol = colnames[location] << getname;
);
我需要选择第 57 到 113 列,但由于某种原因,当我通过关闭脚本执行此操作时,我得到的值不正确。
Re: 跨多列的每一行的最大值和源列的对应名称// this example uses JMP 13 data table indexing
dt = New Table( "Untitled",
New Column( "a", Numeric, Set Values( [1, 33, 1] ) ),
New Column( "b", Numeric, Set Values( [2, 2, 2] ) ),
New Column( "c", Numeric, Set Values( [333, 1, 0] ) ),
New Column( "maxval", numeric ),
New Column( "maxcol", Numeric )
);
colnames = dt << getcolumnnames;
For Each Row(
r = Row();
// 1::3 means columns 1 through 3. {a,b,c} would also work.
location = Loc Max( dt[ r, 1 :: 3] ); // location of maximum value in array
maxval = dt[r, location];
maxcol = colnames[location] << getname;
);
Data table with maximum value from row and name of maximum column for row具有来自行的最大值和行的最大列名称的数据表
早前关于数据表下标的帖子
Re: 跨多列的每一行的最大值和源列的对应名称寻找完全相同的解决方案。
对于每一行,找到最大值并返回列名,这样我就可以对结果数据进行统计。
例如,查找列名显示为最大值的次数、对最大值有贡献的列数、STD DEV 等。