标签: grouping

awk 桶中的直方图

考虑我有以下文件..

1 a
1 b
1 a
1 c
1 a
2 a
2 d
2 a
2 d
Run Code Online (Sandbox Code Playgroud)

我想在桶内有一个直方图...例如,如果桶是 1 那么输出将是

a 3
b 1
c 1
a 2
d 2
Run Code Online (Sandbox Code Playgroud)

对于桶 2...我们有

a 5
b 1
c 1
d 2
Run Code Online (Sandbox Code Playgroud)

我想用 awk 来做,但我真的卡住了......这是我的代码:

awk '
    {A[$1]} count [$2]++ 
    {for(i in A) {print i,A[i]}
    }' test
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?

谢谢,

阿米尔。

awk grouping

1
推荐指数
1
解决办法
3016
查看次数

如何通过Sql Server将多行分组为一行

可能的重复:
在 Microsoft SQL Server 2005 中模拟 group_concat MySQL 函数?

我有 2 张像这样的

班级表:
在此输入图像描述

学生表:
在此输入图像描述

我想加入两个表,但我想要像这样的结果
ClsName StdName
A George
B Jenifer,Anjel,Alex
C Alex,Joe,Michael


如何才能做到这一点?
事实上,对于每个班级,我希望有一排带有不同学生姓名的行

sql-server grouping

1
推荐指数
1
解决办法
2万
查看次数

如何使用分组功能使用 ExpandAll 和 CollapseAll 进行分组网格

我正在尝试使用expandAll() 和collapseAll() 进行分组网格Ext 4.1

但它在覆盖后不起作用:出现错误 ExpandAll() is not Defined

            Ext.override(Ext.grid.feature.Grouping, {
                  collapseAll: function() {
                    var self = this, view = self.view;
                    view.el.query(self.eventSelector).forEach(function (group) {
                      var group_body = Ext.fly(group.nextSibling, '_grouping');
                      self.collapse(group_body);
                    });
                  },

                  expandAll: function() {
                    var self = this, view = self.view;
                    view.el.query(self.eventSelector).forEach(function (group) {
                      var group_body = Ext.fly(group.nextSibling, '_grouping');
                      self.expand(group_body);
                    });
                  }
                });
Run Code Online (Sandbox Code Playgroud)

这是我的视图文件:

 Ext.define('MCT.view.MyGrid',
   {
     extend:'Ext.grid.Panel',
     initComponent:function(){
       var me  = this;
       this.bbar = [{xtype:'button',text:'Expand All', handler:function(){

          me.features[0].expandAll();

          this.callParent(arguments);


        }}];
     },
     features : [{
        ftype : 'grouping',
                    groupHeaderTpl :'.......', …
Run Code Online (Sandbox Code Playgroud)

grid grouping extjs extjs4

1
推荐指数
1
解决办法
9502
查看次数

如何为rdlc中的每个组创建序列号?

我在 rdcl 报告中使用 rownumber(nothing) 创建了一个带有序列号的报告。因为,我在报告中使用了一个组,所以序列号与前一组继续,我得到的报告如下

组 1 1 值
             2 值
             3 值

组2 4值
             5值
             6值

但我需要它就像

组 1 1 值
             2 值
             3 值

组 2 1 值
             2 值
             3 值

我什至尝试使用 RunningValue 函数。可以按照我需要的方式实现吗?

grouping reportviewer rdlc row-number

1
推荐指数
1
解决办法
1万
查看次数

C#中枚举成员的联合

假设我有一个enum BasicType,其定义如下:

    public enum ObjectType{
        A = 1,
        B = 2,
        C = 3,
    }
Run Code Online (Sandbox Code Playgroud)

BasicType 标识执行任何 的三元分类Object。随后,我意识到对象AB需要以与C类似的方式处理,因此我定义了另一个enum ObjectGroupType如下:

public enum ObjectGroupType
{
   AB = 1,
   C = 2,
}
Run Code Online (Sandbox Code Playgroud)

使用新的枚举,我可以将几种已知类型的对象归为一个。因此,当我收到各种类型的对象流时,我实际上会识别它们是属于 AB 类型还是 C 类型。有没有优雅的解决方法?例如,我能否为 A 和 B 中的 A 和 B 分配相同的枚举值ObjectGroupType?:

编辑1:我无法找到相似的问题在这里

编辑 2:感谢 Maurice 的建设性意见——从你的回答中得到提示,我想出了这个重新定义的ObjectGroupType.

 public enum ObjectGroupType
 {
    AB = ObjectType.A | ObjectType.B
    C = 2,
 } …
Run Code Online (Sandbox Code Playgroud)

c# enums grouping

1
推荐指数
1
解决办法
2322
查看次数

分组中第一行和最后一行之间的差异

我从非常复杂的查询中获取了这张表,也就是说,它不可能自己加入。行按时间降序排列。

type, value, time
+---+----+
| 2 |  2 |
| 2 |  7 |
| 3 | 20 |
| 3 | 16 |
+---+----+ 
Run Code Online (Sandbox Code Playgroud)

我需要计算每个类型分组的第一个和最后一个值之间的差异,在给定的示例中,这会给我

+---+----+
| 2 | -5 |
| 3 | 4  |
+---+----+  
Run Code Online (Sandbox Code Playgroud)

可行吗?

sql postgresql grouping group-by

1
推荐指数
1
解决办法
1142
查看次数

将一列上的行分组并从另一列创建嵌套数组

我有一个看起来像这样的数组:

[
    [
        'name' => 'Umber',
        'reason' => 'No data',
        'id' => '12'
    ],
    [
        'name' => 'Jakar',
        'reason' => 'Wrong format',
        'id' => '12'
    ],
    [
        'name' => 'Lane',
        'reason' => 'No data',
        'id' => '12'
    ],
    [
        'name' => 'Jake',
        'reason' => 'Not found',
        'id' => '13'
    ],
    [
        'name' => 'Jame',
        'reason' => 'Wrong name',
        'id' => '13'
    ],
    [
        'name' => 'Joe',
        'reason' => 'No data',
        'id' => '13'
    ]
];
Run Code Online (Sandbox Code Playgroud)

如果 id 值相同,我想要做的是将这些元素分组在一个表格行中:

12 | …
Run Code Online (Sandbox Code Playgroud)

php foreach merge grouping multidimensional-array

1
推荐指数
1
解决办法
2279
查看次数

对于每个文档,从数组中检索带有 $max 字段的对象

我的收藏中有以下文件。每个文档都包含有关特定位置的历史天气数据:

{
'location':'new york', 
'history':[
    {'timestamp':1524542400, 'temp':79, 'wind_speed':1, 'wind_direction':'SW'}
    {'timestamp':1524548400, 'temp':80, 'wind_speed':2, 'wind_direction':'SW'}
    {'timestamp':1524554400, 'temp':82, 'wind_speed':3, 'wind_direction':'S'}
    {'timestamp':1524560400, 'temp':78, 'wind_speed':4, 'wind_direction':'S'}
    ]
},
{
'location':'san francisco', 
'history':[
    {'timestamp':1524542400, 'temp':80, 'wind_speed':5, 'wind_direction':'SW'}
    {'timestamp':1524548400, 'temp':81, 'wind_speed':6, 'wind_direction':'SW'}
    {'timestamp':1524554400, 'temp':82, 'wind_speed':7, 'wind_direction':'S'}
    {'timestamp':1524560400, 'temp':73, 'wind_speed':8, 'wind_direction':'S'}
    ]
},
{
'location':'miami', 
'history':[
    {'timestamp':1524542400, 'temp':84, 'wind_speed':9, 'wind_direction':'SW'}
    {'timestamp':1524548400, 'temp':85, 'wind_speed':10, 'wind_direction':'SW'}
    {'timestamp':1524554400, 'temp':86, 'wind_speed':11, 'wind_direction':'S'}
    {'timestamp':1524560400, 'temp':87, 'wind_speed':12, 'wind_direction':'S'}
    ]
}
Run Code Online (Sandbox Code Playgroud)

我想获取每个位置(或多或少)的最新天气数据列表,如下所示:

{
'location':'new york', 
'history':{'timestamp':1524560400, 'temp':78, 'wind_speed':4, 'wind_direction':'S'}
},
{
'location':'san francisco', 
'history':{'timestamp':1524560400, 'temp':73, …
Run Code Online (Sandbox Code Playgroud)

grouping mongodb aggregation-framework

1
推荐指数
1
解决办法
1008
查看次数

在 R 中使用 ggscatter 由一组着色

我正在使用 ggpubr 库中的 ggscatter 函数来制作散点图。我的数据框看起来像这样

1   a   b   chr17   +   0.003   0.005   0,2 282232  4,0 253259  non_sig
10  a   b   chr22   -   0.733   0.6855  16,17   3,3 24,45   11,4    non_sig
12  a   b   chr13   +   0.7625  0.7965  22,14   1,7 7,18    1,4 non_sig
14  a   b   chr13   +   0.4555  0.369   20,16   19,12   4,23    17,11   non_sig
15  a   b   chr13   +   0.488   0.384   27,15   19,12   7,18    17,11   non_sig
16  a   b   chr16   -   0.9715  0.978   200141  3,2 260280  3,3 non_sig
21  a   b …
Run Code Online (Sandbox Code Playgroud)

grouping r ggpubr

1
推荐指数
1
解决办法
5192
查看次数

使用 rbind 在循环中添加 0 个值

我无法正确编码循环以将行添加到小数据集。

假设我有以下名为“颜色”的数据框:

color   count   group
Blue      3       1
Blue      2       2
Red       2       2
Green     1       1
Run Code Online (Sandbox Code Playgroud)

现在我需要为每列添加 0 个值,以便所有组都有每种颜色,也就是它应该看起来像:

color   count   group
Blue      3       1
Blue      2       2
Red       2       2
Green     1       1
Red       0       1 
Green     0       2
Run Code Online (Sandbox Code Playgroud)

我试图做的最接近我想要的解决方案的是:

color.u <- unique(colors$color)

color.z<- function(x){
  if(x %in% colors$color[colors$group == "1"] == F ) {
    rbind(colors, c(x, 0, "1"))
    }
if(x %in% colors$color[colors$group == "2"] == F ) {
    rbind(colors, c(x, 0, "2"))
    }
}

sapply(color.u, function(x) color.z(x))
Run Code Online (Sandbox Code Playgroud)

这个函数返回的是整个数据集,最后只有两个零值之一。我明白为什么这是一个错误,我相信解决方案很简单,但我不知道如何纠正它。有什么建议? …

grouping loops r sapply rbind

1
推荐指数
1
解决办法
84
查看次数