Analyzing subsets

Tags
Summary

Make accumulator variables for each subset, and an If for processing them.

Situation

You want to separate out data subsets, like old goats, or goats who can code.

Needs
  • A data set, in a CSV file, or a Range.
  • Rules for defining subsets, like goats who are younger than 35, goats between 35 and 55, and goats older than 55.
Provides

Different accumulator variables (totals and counts) for each subset.

Action

Create accumulator variables for each subset. Initialize them. In a loop, add Ifs to separate out each group. An example, for three age groups:

  • 'Loop across goats.
  • For sGoatIndex = 1 To sNumberValidRecords
  •     If asAge(sGoatIndex) < 35 Then
  •         'Accumulate data for young goats.
  •         sNumberYoung = sNumberYoung + 1
  •         sTotalFollowersYoung = sTotalFollowersYoung+ asTwitterFollowers(sGoatIndex)
  •         sTotalTweetsYoung = sTotalTweetsYoung + asTweets30Days(sGoatIndex)
  •         sTotalAgeYoung = sTotalAgeYoung + asAge(sGoatIndex)
  •     ElseIf asAge(sGoatIndex) < 55 Then
  •         'Accumulate data for middle-aged.
  •         sNumberMiddleAged = sNumberMiddleAged + 1
  •         sTotalFollowersMiddleAged = sTotalFollowersMiddleAged + asTwitterFollowers(sGoatIndex)
  •         sTotalTweetsMiddleAged = sTotalTweetsMiddleAged + asTweets30Days(sGoatIndex)
  •         sTotalAgeMiddleAged = sTotalAgeMiddleAged + asAge(sGoatIndex)
  •     Else
  •         'Accumulate data for old goats.
  •         sNumberOld = sNumberOld + 1
  •         sTotalFollowersOld = sTotalFollowersOld + asTwitterFollowers(sGoatIndex)
  •         sTotalTweetsOld = sTotalTweetsOld + asTweets30Days(sGoatIndex)
  •         sTotalAgeOld = sTotalAgeOld + asAge(sGoatIndex)
  •     End If
  • Next sGoatIndex
Where referenced