The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Calculating the statistical mode
Discuss Calculating the statistical mode in the C Programming forum on Dev Shed. Calculating the statistical mode C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 6th, 2002, 05:34 PM
|
|
Contributing User
|
|
Join Date: Apr 2002
Location: new york
Posts: 84
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
|
Calculating the statistical mode
how do i find the mode of a list?
by this i mean the value that appears the most in a particular list.
for example:
List (array): 1, 2, 3, 3, 3, 5, 5, 10
Mode : 3
or
List (array): 1, 2, 3, 3, 3, 5, 5, 5
Mode: 3 and 5
thank you.
|

November 20th, 2002, 07:56 AM
|
|
Junior Member
|
|
Join Date: Nov 2002
Posts: 10
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Perhaps you should create a list (i mean the data structure where every element has a pointer to the next element) which will contain two numbers - first is the value of an item in your original list, and second is the number of times you have encountered that value in your original list.
I hope my bad English and too complex phrase construction will not be a barrier between out developing minds %-[]

|

November 20th, 2002, 08:01 AM
|
|
Junior Member
|
|
Join Date: Nov 2002
Posts: 10
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
as for your example - you'll have 4 nodes in your generated list, with values
1 1
2 1
3 3
5 3
respectively (pointers included).
|

November 21st, 2002, 11:11 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
!
I wrote a program that found the mean, median, mode and range =) here is the part where it finds the mode:
Code:
void mode(double* nums, unsigned int choice)
{
unsigned int index;
int count=0;
int max =0;
for(index=0; index<choice; index++)
{
if(nums[index]==nums[index+1])
count++;
else
{
if(count>max)
max=count;
count=0;
}
}
count=0;
for(index=0; index<choice; index++)
{
if(nums[index]==nums[index+1])
count++;
else
{
if(count==max)
cout<<"Mode(s):\t" <<nums[index]<<"\n";
count=0;
}
}
}
:] hope this helps
|

November 22nd, 2002, 02:25 AM
|
|
Junior Member
|
|
Join Date: Nov 2002
Posts: 10
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
nonono
It will return only the count of the longest sequence of identical numbers.
But as I understand, you need to return the VALUE which is the most frequently appears in the whole sequence.
e.g. for a sequence
1, 2, 3, 4, 2, 4, 4, 2
your function will return THE COUNT 2 (of a value 4)
but the modes are THE VALUES 2 and 4 (appear 3 times both)
|

November 23rd, 2002, 10:40 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
i am not really sure what u are tryin to say 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|