Dear all,
I have one question arise in my mind while i am making my project.

I have one column "AGE" is there.So many values are stored in this column ranging from 0-100.

I also have find frequency of each age like

age=5 comes how many times in my column
age=10 comes how many times in my column

So my question is how can i make a group of this age so can make similar rows by this columns.

my csv file has following values
age,job_code,pincode,gender
12,0,32156,M
12,0,32154,M
10,1,32154,F
10,0,32156,M
8,0,32156,M

how can i decide that if i make group of age having age between [8-12] so all records will become similar?

please reply as soon as possible.

Thanking you.

Create a class with all of the values, call it AgeGroup. Create a map<int,AgeGroup> object where the int part is the age, and the object is the other member. Then read each csv record into an instance of the object, and insert that into the map. Example (not complete, won't compile):

map<int,AgeGroup> ageList;

while (not-done-reading-csv)
{
    AgeGroup member = read-csv-record;
    ageList[member.getAge()] = member;
}

This will give a list of records, nicely sorted by age. Then, counting the number of members of each age, etc is a matter of iterating through the list.

Sort them & make a seperate table according to different age categories for your convenience.

Edited 4 Years Ago by Gaqua77

thanks for your reply.

But my problem is there is not equal group of age.
There might be possible if i create group of [0-5] or [5-15] or [5-9] then more records become similar.

so problem is how can i decide that divide age into agegroup in [0-5] or [5-15] maximum records will become similar?

thanks for your reply.

But my problem is there is not equal group of age.
There might be possible if i create group of [0-5] or [5-15] or [5-9] then more records become similar.

so problem is how can i decide that divide age into agegroup in [0-5] or [5-15] maximum records will become similar?

First, how would you divide a group? Something simple may be done below...

int groupNumber = 5;
int interval = (maximumAge - minimumAge) / groupNumber;
// sort all data by age
// then iterate through each of the data to get the group
MyClass[] data = getData();  // assuming that getData() will return all data in the class
int currentValue = minimumAge;
int counter = interval;
for (MyClass d : data) {
  if (d.age != currentValue) {
    counter--;
    if (counter==0) {
      // new group now, create a new group and add this data to the group
      counter = interval;  // reset counter
    }
    else {
      // still in the same group, add to the current group
    }
  }
  else {  // still in the group
    // add to the current group
  }
}

Edited 4 Years Ago by Taywin

This article has been dead for over six months. Start a new discussion instead.