為組中的獨特案例添加計數器大家好,
為此,我如何編寫一個整數值計數器來增加 A 組中 B 列中的唯一值?

到目前為止,這是我嘗試過的:
dt_Table1 = Data Table("Table1");
dt_Table1 << New Column("Dataset", Numeric, "Nominal", Set Selected);
Sum1 = dt_Table1 << Summary(Group(:Group, :Date));
Sum2 = Sum1 << Summary(Group(:Group));
:N Rows << Set Name("N Datasets in Group");
dt_Table1 << Update(
with(Data Table(Sum2)),
Merge Same Name Columns
Match Flag(0),
Suppress foruma evaluation(0),
By Matching Columns(:Group = :Group),
Drop multiples(1, 0),
Include Nonmatches(0, 0),
Preserve main table order(1)
);
dt = dt_Table1;
For(i = 1, i <= :N Rows(dt), i++,
While(Group_Number = GetValue(:Group[i]),
N == Get Value(dt, :N Datasets in Group[i]),
For(j = 1, j <= N, j++,
:Dataset << Set Value == (j),
),
Group_Number = Group_Number + 1,
),
);
輸出:


自動化和腳本基礎數據分析與建模回复:為組中的獨特案例添加計數器您應該能夠使用 Col Rank()、Col Cumulative Sum、Col Min() 等函數的某種組合來執行此操作。 根據您的示例,Col Rank() 或 Col Cumulative Sum(1, ) 應該足夠了(任何組中都沒有重複日期)。
第 3 列使用 Col Rank 和 Column 4 Col Cumulative Sum 和 Column 5 一個更複雜的公式的一個選項
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(8),
Compress File When Saved(1),
New Column("g", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 1, 1, 2, 2, 2, 2])),
New Column("d", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4, 1, 2, 2, 3])),
New Column("r", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4, 1, 2, 2, 3])),
New Column("Column 3", Numeric, "Continuous", Format("Best", 12), Formula(Col Rank(:d, :g))),
New Column("Column 4", Numeric, "Continuous", Format("Best", 12), Formula(Col Cumulative Sum(1, :g)))
);
dt << New Column("Column 5", Numeric, Continuous, Formula(
Col Cumulative Sum(
If(Row() == Col Min(Row(), :g, :d),
1
,
.
),
:g
)
));

回复:為組中的獨特案例添加計數器謝謝亞爾莫!你的方式絕對更乾淨。我不完全遵循邏輯,但我看到它有效!
注意:我找到了另一種方法,它也使用了 Col Cumulative Sum()。比你的慢。多個子表和一個連接...
Summary1 = Table1 << Summary(Group(:Group, :Date));
Summary2 = Summary1 << Summary(Group(:Group, :Date));
Summary2 << 新列(“數據集”,
數字,
“標稱”,
設置選中
);
:Dataset << Formula(Col Cumulative Sum( :N Rows, :Group ) );
//加入表1
表 1 << 加入(
與(數據表(摘要2)),
全選),
選擇(
:數據集
),
通過匹配列( :Run = :Run ),
丟棄倍數( 1, 0 ),
包括不匹配項 ( 0, 0 ),
保留主表順序(1),
輸出表名("Table2")
);
回复:為組中的獨特案例添加計數器我用這個公式創建了一個新專欄。
如果(排() == 1個,
1個,
如果( :ID ==落後( :ID, 1個),
落後( :姓名( “身份證號碼” ) ) + 1個, 1個))
這假定您的“ID”列按順序排序。
ID的Count,column是用上面的公式新建的列名
回覆:為群組中的獨特案例添加計數器嗯,公式編輯器似乎缺少一個N 口類別功能與GroupBy 選項。
希望正在等待榮譽:
新的 JSL 功能:Col N 類別
回覆:為群組中的獨特案例添加計數器這是一個小腳本,用於產生 A 列中 B 列中找到的唯一值的數量
Names Default To Here( 1 );
dt = new table("Example",
New Column("A", character),
New Column("B", character)
);
charList = {"A","B","C","D","E","F","G","H","I","J"};
dt << add rows(25);
for each row(
:A = char(random integer(1,5));
:B = charList[random integer(1,10)]
);
dt << New Column( "count",
set each value(
As Constant( Summarize( dt, bygroup = by( :a, :p</img> ) ) );
N Items( Loc( bygroup[1], :a ) );
)
);回覆:為群組中的獨特案例添加計數器很好的解決方法:)
(p -> b)
但失蹤的N 口類別還很痛。 可以添加一個自訂功能N 口類別(: col, <{...}>)
可選清單可用於指定用作 by - 的列/子組,就像前面範例中的 :a 一樣。
誰知道如何在匯總函數中引用列?
自訂函數 - 如何引用列
回覆:為群組中的獨特案例添加計數器通常也可以使用不同Col Something() 函數的一些奇怪組合(由於進行了比較,可能不是最快的,如果我沒記錯的話,你不應該以這種方式使用Col 函數,即使它是最好的方法之一使用它們)。
dt << New Column("C", Formula(
Col Sum(Row() == Col Min(Row(), :A, :B), :A);
));
回覆:為群組中的獨特案例添加計數器
可以添加一個自訂功能N 口類別(: col, <{...}>)
不是以乾淨和漂亮的方式建立具有 byVar 的統計自訂(公式)函數,用於立即計算自訂列公式或快取行之間的值的選項或函數
回覆:為群組中的獨特案例添加計數器
@jthi寫道:
不是以乾淨和漂亮的方式
哎喲!
我想添加自訂N 口類別函數使其在右鍵單擊“新公式列”功能表中可用。
所以,如果需要額外的表達式()呼叫函數時圍繞列的表達式,沒有機會得到正確的結果嗎?
啊…
真正令人驚訝的是,花了這麼長時間才添加缺少的內容N 口類別
回覆:為群組中的獨特案例添加計數器驚人的!
根據表的結構,速度會快很多數量級:)
但距離問題的解決還很遙遠右鍵點擊新公式欄菜單 :(
Names Default To Here( 1 );
dt = new table("Example",
New Column("A", character),
New Column("B", character)
);
dt << add rows(20000);
for each row(
:A = char(random integer(1,5));
:B = char(random integer(1,1000));
);
t0 = hptime();
dt << New Column( "count",
set each value(
As Constant( Summarize( dt, bygroup = by( :a, :b) ) );
N Items( Loc( bygroup[1], :a ) );
)
);
(hptime() -t0)/1000000; //~ 1min
t0 = hptime();
dt << New Column("C", set each value(
Col Sum(Row() == Col Min(Row(), :A, :B), :A);
));
(hptime() -t0)/1000000; // < 1sec回覆:為群組中的獨特案例添加計數器好消息:JMP19 將提供唯一 N 列() :
https://community.jmp.com/t5/JMP-Wish-List/Col-N-Categories/idc-p/870972/highlight/true#M7292
它將透過新的公式列選單提供:
