這裡有幾種方法可以做到這一點。但由於下面的示例實際上僅基於 JMP 的主要功能,因此我強烈建議您閱讀 JMP 文檔庫中的發現 JMP 和使用 JMP 文檔,這些文檔位於“幫助”下拉菜單下。
Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "Score Category",
character,
formula(
If(
:Score < .6, "0.50-0.59",
:Score < .8, "0.60-0.79",
:Score < .9, "0.80-0.89",
"0.90-1.00",
)
)
);
dtSum = dt << Summary(
Group( :Group, :Score Category ),
Sum( :Count ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 )
);
dtSum << delete columns( :N Rows );
dtSum:Name( "Sum(Count)" ) << set name( "Total_Count" );
// or
dt:score << set property(
"value labels",
{0.5 <= "0.50-0.59" < 0.6, 0.6 <= "0.60-0.79" < 0.8, 0.8 <= "0.80-0.89" < 0.9, 0.9
<= "0.90-1.00" <= 1}
);
dtSum = dt << Summary(
Group( :Group, :Score ),
Sum( :Count ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 )
);
dtSum << delete columns( :N Rows );
dtSum:Name( "Sum(Count)" ) << set name( "Total_Count" );我將使用交互式方法來捕獲此腳本。 首先我們從數據表開始:

我把 Count 去掉了,因為我們不需要它,但如果它在那裡也沒什麼壞處。
我選擇了“分數”列,然後導航到“列”、“實用程序”、“創建分箱公式”:

並將 Offset 設置為 0.5,bin width 設置為 0.1:

右鍵單擊新列(分箱得分)並複制列屬性:

然後打開一個新的腳本窗口並粘貼 (ctrl-V),這會生成以下 JSL:
Add Column Properties(
Value Labels(
{-0.5 = "-0.5 — -0.4", -0.4 = "-0.4 — -0.3", -0.3 = "-0.3 — -0.2", -0.2 =
"-0.2 — -0.1", -0.1 = "-0.1 — 0", 0 = "0 — 0.1", 0.1 = "0.1 — 0.2", 0.2 =
"0.2 — 0.3", 0.3 = "0.3 — 0.4", 0.4 = "0.4 — 0.5", 0.5 = "0.5 — 0.6", 0.6 =
"0.6 — 0.7", 0.7 = "0.7 — 0.8", 0.8 = "0.8 — 0.9", 0.9 = "0.9 — 1", 1 =
"1 — 1.1", 1.1 = "1.1 — 1.2", 1.2 = "1.2 — 1.3", 1.3 = "1.3 — 1.4", 1.4 =
"1.4 — 1.5", 1.5 = "1.5 — 1.6", 1.6 = "1.6 — 1.7", 1.7 = "1.7 — 1.8", 1.8 =
"1.8 — 1.9", 1.9 = "1.9 — 2"}
),
Use Value Labels( 1 ),
Formula( 0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 ) )
)這裡有兩件事:我們不關心任何小於 0.5 的分數(它們在您的描述中不存在)或大於 1,因此我們可以稍微更改屬性並編輯標籤名稱以匹配您想要的。 我還添加了一個 If 語句來捕獲分數恰好為 1 的邊緣情況
Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);(順便說一句,這些標籤在技術上並不准確,因為 0.599 將被標記為 0.5 到 0.59 之間)
我們可以圍繞此代碼片段包裝一些代碼以使其可重用,其中我們使用當前的數據表,添加一個名為 Score Binned 的新列,並將這些屬性添加到該列:
dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);現在,回到我們的表格,“表格”>“摘要”將我們帶到我們想去的地方。 我們將 Group 和 Score Binned 放在 Group 中,這就是我們實際需要的:


現在,N Rows 就是我們想要的,它只是命名錯誤,所以讓我們雙擊左側的“Source”一詞並複製表創建腳本,並將命名表引用替換為我們的工作表“dt”,並在變量“summ”中捕獲新表:

dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);
summ = dt << Summary(
Group( :Group, :Score Binned ),
Freq( "None" ),
Weight( "None" )
);最後,根據需要將 N Rows 重命名為“Total_Count”:
dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);
summ = dt << Summary(
Group( :Group, :Score Binned ),
Freq( "None" ),
Weight( "None" )
);
summ:"N Rows"n << Set Name("Total_Count");現在,關閉匯總表,從源表中刪除 Score Binned 列,然後測試腳本:

最後的 JSL 再次:
dt = Current Data Table();
dt << New Column("Score Binned", Character);
dt:"Score Binned"n << Add Column Properties(
Value Labels(
{0.5 = "0.5 — 0.59", 0.6 = "0.6 — 0.69", 0.7 = "0.7 — 0.79", 0.8 = "0.8 — 0.89", 0.9 =
"0.9 — 1"}
),
Use Value Labels( 1 ),
Formula(
If(
(0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )) == 1, 0.9,
0.5 + 0.1 * Floor( (:Score - 0.5) / 0.1 )
)
)
);
summ = dt << Summary(
Group( :Group, :Score Binned ),
Freq( "None" ),
Weight( "None" )
);
summ:"N Rows"n << Set Name("Total_Count");對您附加的數據進行了測試,我確實注意到了:flushed_face:
