简体   繁体   English

如何在J中将相等值分组?

[英]How to group equal values in J?

   (= <@#"1 0 ~.) 3 2 3 3 4
+-----+-+-+
|3 3 3|2|4|
+-----+-+-+

What other ways are there? 还有什么其他方式? I mostly don't like the part where it says "1 0 . 我大多不喜欢上面写着"1 0的部分。

The adverb key ( /. ) groups the right argument as specified by the left argument and applies a verb to each group. 副词/. )将左参数指定的右参数分组,并将动词应用于每个组。 If you give it the same left and right argument you can apply the verb box ( < ) to group all the equal items 如果给它相同的左右参数,则可以应用动词< )将所有相等的项分组

   </.~ 3 2 3 3 4
┌─────┬─┬─┐
│3 3 3│2│4│
└─────┴─┴─┘

You could easily sum the groups instead: 您可以轻松地对各组求和:

   +//.~ 3 2 3 3 4
9 2 4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM