如何查找给定列中任意两列具有相同值的行?例如这里的第1——第3列:
dt = Open( "$SAMPLE_DATA\Missing Data Pattern.jmp" );
dt<<NEW column=""></NEW>

谢谢!
自动化和脚本编写回复:如何查找给定列中任意两列具有相同值的行?感谢您的帮助!

回复:如何查找给定列中任意两列具有相同值的行?@lwx228 , @tx尼尔森,
就是图个好玩儿...
- 添加@lwx228示例数据到@tx尼尔森,见附件JMP数据表JN_AdjacentPlus.jmp
- 下面的脚本嵌入在表中。 该脚本名为“查找具有匹配相邻列的任何行”,实际上匹配的值不为空。
- 注意#1:此脚本将采用任意数量的列。 数据表中的列不需要相邻,只需更改xmat定义中的列规范即可。
- 注意 #2:Abs(x1-x2) 确保相邻匹配返回零并且所有其他值都 > 0。
- 注意#3:Vmin() 查找矩阵每列的最小值。 因此, transpose( Vmin(transpose(Abs(x1-x2))) ) 返回 Abs(x1-x2) 的行最小值
- 注意#4:Loc( vec ==0 ) 返回值为 0 的行号。
- 注意#5:吉姆的解决方案找到任何匹配项,该脚本找到相邻的匹配项。
Names Default to Here(1);
dt = current data table();
xmat = dt[0,1::4];
nc = ncol(xmat);
x1 = xmat[0,1::nc-1];
x2 = xmat[0,2::nc];
idx = Loc( Transpose(Vmin(Transpose(abs(x1-x2)))) == 0);
dt << New Column("t1", numeric, continuous);
:t1[idx]=1;
回复:如何查找给定列中任意两列具有相同值的行?谢谢吉姆!
Mode( dt[i, 1::3] || [-999] ) == -999
回复:如何查找给定列中任意两列具有相同值的行?这是对此问题的不同看法。我正在使用 Mode() 函数来查看模式是什么。如果存在实际模式,则意味着至少有 2 个值匹配,因此列 t1 将设置为 1。请参阅 JSL 注释以获得更完整的说明。
我附上了用于测试的数据表。
Names Default To Here( 10 );
dt = Current Data Table();
New Column( "t1" );
For( i = 1, i <= N Rows( dt ), i++,
// add a value to the matrix that is less
// than any value in the data table. If
// the mode() function does not find an
// actual mode, it returns the smallest
// value from the matrix, so if that is
// the value returned, you know there
// are not at least 2 values that equal
// each other in the columns
If( Mode( dt[i, 0] || [-999] ) == -999,
dt:t1[i] = .,
dt:t1[i] = 1
)
);
回复:如何查找给定列中任意两列具有相同值的行?
dt = Current Data Table();
x = dt << Get As Matrix();
For( i = 1, i <= N Row( dt ), i++,
For( j = 1, j <= 2, j++,
If( x[i, j] == x[i, j + 1],
x[i, 5] = 1;
Break();
)
)
);
dt[0, 0] = x;