以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何取众数  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=88473)

--  作者:527383691
--  发布时间:2016/8/3 15:45:00
--  [求助]如何取众数
表达式列里面取众数的函数是什么?
--  作者:cbt
--  发布时间:2016/8/3 16:31:00
--  
\'参考 字典
Dim ls() As String = "a,a,b,b,c,d,e".Split(",")
Dim dct As new Dictionary(of String,Integer)
For Each a As String  In ls
    If dct.ContainsKey(a) = False Then
         dct.Add(a,1)
    Else
           dct(a) = dct(a)+1
        output.show("是中暑: " & a)
    End If
Next
--  作者:大红袍
--  发布时间:2016/8/3 16:43:00
--  

 表达式无法取众数的函数,要用代码,参考

 

Dim dic As new Dictionary(Of String, Integer)
Dim count As Integer = 0
For Each dr As DataRow In DataTables("表A").Select("")
    Dim v As String = dr("第三列")
    If dic.ContainsKey(v) = False Then
        dic.Add(v, 1)
    Else
        dic(v) += 1
    End If
    If dic(v) > count Then
        count = dic(v)
    End If
Next
For Each key As String In dic.keys
    If dic(key) = count Then
        msgbox(key & " " & dic(key))
    End If
next


--  作者:527383691
--  发布时间:2016/8/5 17:28:00
--  
谢谢