Picking out the top groups in terms of average population size
In many instances, we will only want to look at the top categories, especially when there are many demographical categories that have been subsetted. In this example, there are only 24 categories but in other examples, there may be a much larger number of categories.
The dataframe x2
is already sorted by Avg.People
. Since we know that there are 14 enrollment records for each category, we can get the top 10 categories based upon the highest base population by selecting the first 14*10 (or 140) rows. We will store this in a new dataframe, x3
, and save this to disk.
Since we know each group has 14 years, extracting the top 10 groups is easy to calculate. After assigning x2, print the first 15 records and observe that the category break after the first 14 records:
x3 <- x2[1:(14 * 10), ] head(x3,15) cat Avg.Total.Insured Avg.People Year Year.1 Total.People Total Not.Covered <fctr> <dbl> <dbl> <fctr> <...