I have multiple R data sets from which I am pulling the frequency of the occurrence of each number, 1 through 8. The data sets are each only 5 values long though, so not all of the numbers are represented. Here is an example of what one of those lists looks like:
T1
#1 2 3 4 7
#1 1 1 1 1
I am generating multiple of these lists from different sets of 5 numbers, and will be using them in side-by-side figures. In order to standardize the graphing parameters between all these lists, I want them each to have all numbers 1:8 represented, even the missing ones. My ideal result would look like this:
T1
#1 2 3 4 5 6 7 8
#1 1 1 1 0 0 1 0
I have attempted various methods, including:
- Creating a blank list with 1:8 to merge or rbind the existing list with. Merging doesn't work and rbind required the same number of columns
- Generating the list with a factor that includes
levels = 1:8
. This always resulted in a of values 1:8, but not populated with my data
I can't tell if I am trying the right methods but performing them incorrectly, or if there is a different approach. Any help would be appreciated!
Additional Context, per @onyambu:
I am pulling this data from a data.frame where each Column is a person and each of the 5 rows in a number 1-8. And example of the frame is:
Layton Jared Jon Colby Brandon
SC.1 7 4 2 5 3
SC.2 3 7 4 6 1
SC.3 1 8 3 5 4
SC.4 4 3 1 5 8
SC.5 2 8 1 3 7
In order to get each column to a format compatible with a Pie Chart, I am using table(DF[n])
to create the following table:
table(DF[1])
Layton
1 2 3 4 7
1 1 1 1 1
table(DF[2])
Jared
3 4 7 8
1 1 1 2
In order to graph the Pie charts side-by-side with compatible colors and legends, I would like the final result to include missing numbers 1-8 as well. Something like this:
Layton
1 2 3 4 5 6 7 8
1 1 1 1 0 0 1 0
Jared
1 2 3 4 5 6 7 8
0 0 1 1 0 0 1 2