迭代兩個不同大小的數據表並比較匹配值嗨,
我有以下問題:
- 我在單獨的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的新列,它將告訴您是否找到匹配項
表==>加入