如何分隔清單中的符合值你好,
我有一個列表,其中可能包含以下內容,例如:{22, 22, 22, 33, 33}。 我希望能夠取得清單中每個唯一值的數量,例如 22 的數量和 33 的數量。 問題是,我不知道我的清單有多長,也不知道清單中有多少個唯一的數字。 JSL 有沒有辦法概括這個問題的解決方案?
謝謝
自動化和腳本編寫回覆:如何分隔清單中的符合值我相信您的最後一次編輯需要將“my_bigger_list”更改為“my_list”
回覆:如何分隔清單中的符合值你好,
不用擔心,我解決了問題,而您的解決方案不是問題的一部分。 謝謝。
回覆:如何分隔清單中的符合值@pmroz的回應引起了我的興趣。因為我通常會盡量避免使用資料表,因為這樣會帶來開銷。我玩的是計時
names default to here(1);
my_list = {44, 33, 22, 33, 44};
repeat_list = [1, 5, 10, 50, 100, 1000, 2500, 5000, 7500, 10000];
dt_timing = new table("Timings",
new column("List Size"),
new column("Design"),
new column("Loop"),
new column("Summarize"),
);
for(ii=1, ii<=20, ii++,
for(ir = 1, ir <= nitems(repeat_list), ir++,
my_bigger_list = repeat(my_list, repeat_list[ir]);
// using design
st = HPTime();
aa = associative array(my_bigger_list);
keys = aa << Get Keys;
d = design(my_bigger_list, keys);
aa_design = associative array(keys, VSum(d));
time_design = HPTime() - st;
//using a loop
st = HPTime();
aa_loop = associative array(my_bigger_list, repeat(0, nitems(my_bigger_list)));
for(i=1, i<=nitems(my_bigger_list), i++,
aa_loop[my_bigger_list[i]]++;
);
time_loop = HPTime() - st;
//using a data table
st = HPTime();
dt = New Table( "Untitled", invisible, Add Rows( nitems(my_bigger_list) ),
New Column( "Column 1", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( my_bigger_list )
)
);
summarize(dt, unique_value_list = by(:column1), unique_count = count(:column 1) );
close(dt, nosave);
aa_peter = associative array(unique_value_list, unique_count);
time_peter = HPTime()-st;
Eval(EvalExpr(
dt_timing << Add Rows({List Size = Expr(Nitems(my_bigger_list)), Design = Expr(time_design), Loop = Expr(time_loop), Summarize = Expr(time_peter)});
));
);
);
dt_stack = dt_timing << Stack(
columns( :Design, :Loop, :Summarize ),
Source Label Column( "Method" ),
Stacked Data Column( "Timing" )
);
close(dt_timing, no save);
biv = dt_stack << Bivariate(
Y( :Timing ),
X( :List Size ),
group by(:Method),
fit line(),
SendToReport(
Dispatch(
{},
"Bivar Plot",
FrameBox,
{Row Legend(
Method,
)}
),
)
);
顯然這取決於列表的大小。但我在不同的列表大小上分別運行了 20 次,得到了這個

設計是我能找到的最快的方法。我絕對同意@tx尼爾森我不喜歡 Summarize 因為它總是返回字元。
回覆:如何分隔清單中的符合值我是設計的忠實粉絲。
names default to here(1);
l = {22, 22, 22, 33, 33};
l = sort ascending(l);
d = VSuM(design(l));
csum = cumulative sum(d);
lvalues = l[csum];
aa = associative array(lvalues, d);
*編輯*我意識到排序需要花費很多時間,所以這要快得多
names default to here(1);
my_list = {44, 33, 22, 33, 44};
aa = associative array(my_list );
keys = aa << Get Keys;
d = design(my_list , keys);
aa_design = associative array(keys, VSum(d));
*再次編輯(不知道為什麼這讓我如此煩惱)*我不喜歡關聯數組,但這仍然更快
names default to here(1);
my_list = {44, 33, 22, 33, 44};
d = design(my_bigger_list, <<LEVELS></LEVELS>回覆:如何分隔清單中的符合值如果您要循環遍歷文件中的列,為什麼不直接使用製表或摘要命令呢?如果您按另一列將事物分組,則可以將其用作「by」變數。例如:
| ID |
價值 |
| A |
1 |
| A |
2 |
| A |
2 |
| 乙 |
2 |
| 乙 |
3 |
| 乙 |
3 |
| 乙 |
4 |
| 乙 |
4 |
使用製表將 ID 和值列拖曳到行的放置區域上。您需要將 Value 的角色變更為分組變數。這是結果:
| ID |
價值 |
氮 |
| A |
1 |
1 |
| A |
2 |
2 |
| 乙 |
2 |
1 |
| 乙 |
3 |
2 |
| 乙 |
4 |
2 |
因此,對於 A,您有兩個不同的值 (1, 2),以及出現的次數 (1, 2)。對於 B,您有三個不同的值 (2, 3, 4),以及出現次數 (1, 2, 2)。
這是等效的 JSL:
dt = New Table( "Test", Add Rows( 8 ),
New Column( "ID", Character, "Nominal",
Set Values( {"A", "A", "A", "B", "B", "B", "B", "B"} ) ),
New Column( "Value", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [1, 2, 2, 2, 3, 3, 4, 4] ) )
);
dtab = dt << Tabulate(
Show Control Panel( 0 ),
Add Table( Row Table( Grouping Columns( :ID, :Value ) ) ),
invisible
);
dt2 = dtab << Make Into Data Table;回覆:如何分隔清單中的符合值你能發布一些數據和程式碼嗎?
回覆:如何分隔清單中的符合值你好@pmroz ,
我嘗試了您發布的第一個解決方案,它適用於一個文件/清單。 但是,當我將您的程式碼用作函數並循環它時(儘管已初始化所有變數以確保沒有儲存上一次迭代中的任何內容),它似乎不起作用。 我引用一個文件,因為我循環遍歷文件中的一列以獲取正在使用的清單。 當我確保初始化所有列表和變數時,對發生的情況有什麼想法嗎?
回覆:如何分隔清單中的符合值@賈茲,
這是一種使用 Loc() 的替代方法。
MyList = {22,33,22,22,22,33,33,44,44,44,33,22};
AA = Associative Array(MyList);
UniqueVals = AA << Get Keys;
Frequency = {};
for(i = 1, i <= N Items(UniqueVals),i++,
Insert Into(Frequency,N Rows(Loc(MyList,UniqueVals[i])));
);
Show(Frequency);
回覆:如何分隔清單中的符合值請將此建議發佈到社區的願望清單區域。
回覆:如何分隔清單中的符合值我對摘要平台的支持是,分組變數在摘要資料表中保持為與原始資料表中相同的資料類型。在 Summarize() 函數中,它始終以字元值形式傳回,即使指定的 By 列是數字也是如此。
回覆:如何分隔清單中的符合值我同意@pmroz和@tx尼爾森,數據表使這變得容易。
我更喜歡總結()功能結束製表和概括不過為此。
my_list = {22, 22, 22, 33, 33};
dt = New Table( "Untitled",
private,
Add Rows( N Items( my_list ) ),
New Column( "Column 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( my_list )
)
);
summarize(dt, group=by(:column 1), n=count(:column 1));
show(group, n);
回覆:如何分隔清單中的符合值謝謝,
如果 JMP 包含針對清單/關聯陣列的查找符合項目/傳回符合項目功能(就像針對列和行一樣),將會非常有用。
回覆:如何分隔清單中的符合值別忘了總結一下。甚至更短。
my_list = {22, 22, 22, 33, 33};
dt = New Table( "Untitled", invisible, Add Rows( nitems(my_list) ),
New Column( "Column 1", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( my_list )
)
);
summarize(dt, unique_value_list = by(:column1), unique_count = count(:column 1) );
show(unique_value_list, unique_count);
回覆:如何分隔清單中的符合值這是我的變體@pmroz解決方案。這更像是老派的解決方案
my_list = {22, 22, 22, 33, 33};
dt = New Table( "Untitled",
private,
Add Rows( N Items( my_list ) ),
New Column( "Column 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( my_list )
)
);
// Use the Summary Platform to create the aggragate values
dtSum = dt << Summary(
private,
Group( :Column 1 ),
Freq( "None" ),
Weight( "None" )
);
// Create the new lists
unique_value_list = As List( dtSum:column 1 << get values );
unique_count = As List( dtSum:n rows << get values );
Close( dt, nosave );
Close( dtSum, nosave );
Show( unique_value_list, unique_count );回覆:如何分隔清單中的符合值表操作可能是最快的方法。
my_list = {22, 22, 22, 33, 33};
dt = New Table( "Untitled", invisible, Add Rows( nitems(my_list) ),
New Column( "Column 1", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( my_list )
)
);
dtab = dt << Tabulate(Show Control Panel( 0 ),
Add Table( Row Table( Grouping Columns( :Column 1 ) ) ));
dt2 = dtab << Make Into Data Table(invisible);
unique_value_list = dt2:column 1 << get values;
unique_count = dt2:n << get values;
close(dt, nosave);
close(dt2, nosave);
show(unique_value_list, unique_count);回覆:如何分隔清單中的符合值我已經設法使用關聯數組和 << get key 功能來獲取像 {22, 33} 這樣的唯一值的列表,但我仍然不知道如何獲取原始值中每個唯一值的數量列表。