Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,574 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,881 people online right now. Registration is fast and FREE... Join Now!




Median and Mode

 
Reply to this topicStart new topic

Median and Mode

sylina
5 Apr, 2008 - 11:06 PM
Post #1

New D.I.C Head
*

Joined: 7 Feb, 2008
Posts: 11

I haven't started on mode yet, it seems harder. But this is what I've gotten so far for median. I'm not very good at math so I'm starting to confuse myself with what I'm trying to do lol.

CODE
Private Function medianFunc(ByVal arr As ArrayList)

        arr.Sort()

        Dim median As Double
        If arr.Count() Mod 2 = 0 Then
            'odd number of items
            median = arr.Count() \ 2
            Return arr(median)
        
        Else
            'even number of items
            median = (arr(arr.Count() \ 2) + arr(1 + arr.Count() \ 2)) / 2
            Return median


        End If

Oh, side question, do I have to have "as integer" after the (byval arr as arraylist) part? It doesn't give me an error so I'm not sure?

The example I'm using for this is "6, 6, 8, 8, 10, 21"
and it keeps giving me 6 as an answer.

And I'm getting confused when I should use / or \ for dividing.


User is offlineProfile CardPM
+Quote Post

sylina
RE: Median And Mode
6 Apr, 2008 - 06:31 PM
Post #2

New D.I.C Head
*

Joined: 7 Feb, 2008
Posts: 11

Okay I acutally got median figure out now!!! yay.

But I still don't know how to go about doing mode.. I can't picture what the process would be like, so can anyone help with that?
User is offlineProfile CardPM
+Quote Post

jdebord
RE: Median And Mode
7 Apr, 2008 - 12:25 PM
Post #3

New D.I.C Head
*

Joined: 7 Apr, 2008
Posts: 1

Hi,

I'm struggling to learn how to calculate mean and median as well. Would you mind sharing your code?
User is offlineProfile CardPM
+Quote Post

sylina
RE: Median And Mode
7 Apr, 2008 - 09:44 PM
Post #4

New D.I.C Head
*

Joined: 7 Feb, 2008
Posts: 11

Well can you help with mode?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:04AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month