|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
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 %-[] ![]() |
|
#3
|
|||
|
|||
|
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). |
|
#4
|
|||
|
|||
|
!
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 |
|
#5
|
|||
|
|||
|
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) |
|
#6
|
|||
|
|||
|
i am not really sure what u are tryin to say
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Calculating the statistical mode |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|