你好,
我正在嘗試編寫一個腳本,該腳本使用一列來選擇那裡的匹配單元格,然後使用這些選定的行來查找旁邊列中數字的平均值,但我不太確定如何做到這一點。 這是我正在處理的示例表(最後一個平均列是我需要腳本執行的操作):
| 匹配欄: | 數字: | 分組數的平均值 |
| A | 2 | 3 |
| A | 4 | 3 |
| 乙 | 2 | 4 |
| 乙 | 4 | 4 |
| 乙 | 6 | 4 |
| C | 3 | 6 |
| C | 6 | 6 |
| C | 9 | 6 |
| d | 2 | 2 |
| d | 2 | 2 |
您不需要為此編寫腳本。 這列平均值()公式編輯器中的函數將通過分組列計算平均值。
我附上了根據您發布的示例製作的數據表,以便您可以看到它在 JMP 本身中的樣子。

有多種方法可以解決此問題,但我發現最簡單的方法是使用
表格==>總結
進行匯總,然後將匯總數據合併回原始表中。這是一個簡單的腳本,使用您的示例數據來執行此操作
Names Default To Here( 1 );
// Create an example data table
dt = New Table( "Example",
Add Rows( 10 ),
New Column( "Matching Column",
Character,
"Nominal",
Set Values( {"a", "a", "b", "b", "b", "c", "c", "c", "d", "d"} )
),
New Column( "Numbers",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 4, 2, 4, 6, 3, 6, 9, 2, 2] )
)
);
// Pause so one can see the original table
wait(5);
// Summarize the data
dtSum = dt << Summary(
invisible,
Group( :Matching Column ),
Mean( :Numbers ),
Freq( "None" ),
Weight( "None" ),
statistics column name format( "column" ),
Link to original data table( 0 ),
output table name( "Means" )
);
// Adjust items in summary data to allow for proper merging
dtSum << delete columns( "N Rows" );
dtSum:Numbers << Set Name( "Average of grouped numbers" );
// Add the summary data to the original data table
dt << Update( With( dtSum ), Match Columns( :Matching Column = :Matching Column ) );
// Clean up the environment
Close( dtSum, nosave );