迭代两个不同大小的数据表并比较匹配值嗨,
我有以下问题:
- 我在单独的jmp文件中有两个数据表,每个文件都有一列。
- 一张桌子是8排长,而另一张桌子是6440排长。
- 我的目标是遍历8行表中的每个值,并将它们与6440行表中的每个值进行比较,看它们是否匹配。
- 我只是想知道如何做到这一点,因为我想迭代两个表,但它们是不同的大小。我正在考虑使用嵌套的for循环,但我不太确定。
任何帮助,将不胜感激。
Re:迭代两个不同大小的数据表并比较匹配值我在之前的伪代码示例中略有错误,
dtShort:Compare Column[i] > dtLong:Compare Column</CODE></PRE>
<P><SPAN>需要在逻辑上颠倒才能发挥作用</SPAN></P>
<PRE><CODE class=" language-jsl"> dtLong:Compare Column > dtShort:Compare Column[i]
这是一个有效的例子
Names Default To Here( 1 );
dtLong = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Create the short data table
dtShort = New Table( "Short",
New Column( "Target Age", values( {12, 16} ) ),
New Column( "Match", character, values( {"Teenager", "Young Adult"} ) )
);
// Sort the data for illustration of data not being
// in age order
dtLong << sort( by( :Name ), replace table( 1 ) );
// Create a couple of new columns in the data table
dtLong << New Column( "Kind Of Match", character );
dtLong << New Column( "Count" );
// Process the data
For( i = 1, i <= N Rows( dtShort ), i++,
// Find all rows that match the Where Clause
theRowsFound = dtLong << get rows where( dtLong:Age > dtShort:Target Age[i] );
// If some rows were found process
If( N Rows( theRowsFound ) > 0,
// Set a value in the dtLong data table with one statement
// that sets values in multiple rows
dtLong:Kind Of Match[theRowsFound] = dtShort:Match[i];
// Now set values row by row for individual rows that were found
theCount = 1;
For( k = 1, k <= N Items( theRowsFound ), K++,
dtLong:Count[theRowsFound[k]] = theCount;
theCount = theCount + 1;
);
);
);Re:迭代两个不同大小的数据表并比较匹配值感谢您的快速答复。
对于以下部分:
dtLong : Compare Column
你是否介意解释如何访问列中的所有值而不必引用列的每个下标/索引?
Re:迭代两个不同大小的数据表并比较匹配值这是我如何处理它......
// This is pseudo code, but it will give you an idea of the flow
dtShort = Open( "<YOUR short="" data="https://community.jmp.com/" table="">" );
dtLong = Open( "<YOUR long="" data="https://community.jmp.com/" table="">" );
For( i = 1, i <= N Rows( dtShort ), i++,
theRowsFound = dtLong << get rows where( dtShort:Compare Column[i] > dtLong:Compare Column );
If( N Rows( theRowsFound ) > 0,
// Do your processing
);
);</YOUR></YOUR>
Re:迭代两个不同大小的数据表并比较匹配值感谢您的回复。
如果我想检查8行表中的值是什么,你会如何建议解决问题?更大比6440行表中的值?
Re:迭代两个不同大小的数据表并比较匹配值我认为最简单的方法是让JMP为你工作。 如果将表连接到新表中,可以让JMP创建一个名为Match flag的新列,它将告诉您是否找到匹配项
表==>加入