【问题标题】:How to count unqiue combinations of interactions between rows in excel?如何计算excel中行之间交互的唯一组合?
【发布时间】:2014-12-02 03:10:31
【问题描述】:

所以我遇到了一些麻烦,希望有人能提供帮助,我正在尝试模拟天气。

我正在尝试计算 excel 中的分类数据之间发生某些交互的次数,示例数据集:

     Sunny
     Sunny
     Cloudy
     P-Cloudy
     Sunny 
     Rainy
     Cloudy
     Sunny
     Sunny 
     Etc...

所以第一天是晴天,第二天是晴天,第三天是阴天,以此类推。我如何计算每种天气类型变化的次数,即

  Sunny to Sunny     2
  Sunny to P-Cloudy  0
  Sunny to Cloudy    1  
  Sunny to Rainy     1
  Cloudy to P-Cloudy 1 
  Cloudy to Sunny    1
  Cloudy to Rainy    0   Etc..

任何帮助将不胜感激。

【问题讨论】:

    标签: excel


    【解决方案1】:
    Row   A         B       C        D                            E                             F                           G
    1     Today     Tomorrow                        
    2     Sunny     =A3              Sunny                        Cloudy                        P-Cloudy                    Rainy
    3     Sunny     =A4     Sunny    =COUNTIFS(a:a,$D3,b:b,E$2) =COUNTIFS(a:a,$D3,b:b,F$2)  =COUNTIFS(a:a,$D3,b:b,G$2)  =COUNTIFS(a:a,$D3,b:b,H$2)
    4     Cloudy    =A5     Cloudy   =COUNTIFS(a:a,$D4,b:b,E$2) =COUNTIFS(a:a,$D4,b:b,F$2)  =COUNTIFS(a:a,$D4,b:b,G$2)  =COUNTIFS(a:a,$D4,b:b,H$2)
    5     P-Cloudy  =A6     P-Cloudy =COUNTIFS(a:a,$D5,b:b,E$2) =COUNTIFS(a:a,$D5,b:b,F$2)  =COUNTIFS(a:a,$D5,b:b,G$2)  =COUNTIFS(a:a,$D5,b:b,H$2)
    6     Sunny     =A7     Rainy    =COUNTIFS(a:a,$D6,b:b,E$2) =COUNTIFS(a:a,$D6,b:b,F$2)  =COUNTIFS(a:a,$D6,b:b,G$2)  =COUNTIFS(a:a,$D6,b:b,H$2)
    7     Rainy     =A8                     
    8     Cloudy    =A9                     
    9     Sunny     =A10                        
    10    Sunny                         
    

    我希望这会有所帮助。 :)

    好吧,我不想重写它,但我会将所有列引用设为绝对 ($A:$A & $B:$B) 只是为了使复制和粘贴更容易。

    也就是说,C 列中的垂直天数列表是今天列,第 2 行列表是过渡到下一个的天气

    【讨论】:

      【解决方案2】:
      • 只需将您的输入放在 A 列即可。
      • B 列显示了从一种天气到另一种天气的过渡。
      • C 和 D 列按排序顺序显示 出现次数(但有重复)
      • F 和 G 列是您的最终结果

      子model_weather()

      lastrow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row - 1
      
      For i = 1 To lastrow
      Cells(i, 1) = Trim(Cells(i, 1))
      Cells(i, 2).Value = Cells(i, 1) & " to " & Cells(i + 1, 1)
      Cells(i, 3).Value = Cells(i, 1) & " to " & Cells(i + 1, 1)
      Next
      
      Range("C1:C" & lastrow).Sort Key1:=Range("C1:C" & lastrow), Order1:=xlAscending, Header:=xlNo
      
      temp = 1
      
      For i = 1 To lastrow
      If Cells(i, 3) = Cells(i + 1, 3) Then
      temp = temp + 1
      Else: temp = 1
      End If
      Cells(i, 4) = temp
      Next
      
      Range("C1:D" & lastrow).Select
          Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, _
                         Key2:=Range("D1"), Order2:=xlAscending, _
                         Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
      x = 1
      For i = 1 To lastrow
      If Cells(i, 3) <> Cells(i + 1, 3) Then
      Cells(x, 6) = Cells(i, 3)
      Cells(x, 7) = Cells(i, 4)
      x = x + 1
      End If
      Next
      
      End Sub
      

      【讨论】:

        猜你喜欢
        • 2019-06-18
        • 1970-01-01
        • 2023-02-22
        • 1970-01-01
        • 1970-01-01
        • 2018-04-20
        • 1970-01-01
        • 2012-02-10
        • 1970-01-01
        相关资源
        最近更新 更多