Skip to content
Prev 304169 / 398513 Next

Two selections from Bag A

On Aug 26, 2012, at 8:28 AM, darnold wrote:

            
My code from earlier today (that you have not included) showed you how  
to tabulate and construct the BagA entries. I actually did it  by way  
of makine a dataframe from the names of the table and a counts column  
with the table.  In Table 1.1 the two Bags combinations have been  
merge()-ed by their value columns.

 > merge(BagAcombs, BagBcombs, by=1:2, all=TRUE)
       X1   X2 counts.x counts.y
1  -1000   10        7       NA
2  -1000   20        6       NA
3  -1000   30        2       NA
4  -1000   40        2       NA
5  -1000   50        1       NA
6  -1000   60        1       NA
7     10   10       21       NA
8     10   20       42        1
9     10   30       14        2
10    10   40       14        2
11    10   50        7        6
12    10   60        7        7
13    10 1000       NA        1
  .... Rest of  output deleted

That object was assigned to "Combs".
I made the labels numeric. NA values were set to 0.
Calculate and average:

 > Combs$Average <- with( Combs, rowMeans(X1,X2) )
So the second table is aggregated (summed and sorted)  by the distinct  
values in the average-column of the first. (The 7 A 10 x 50 values are  
added to the 12 A 20 x 40 values and the single 1 A 30 x 30 to give 20  
in the 30 row for A). You should create a factor and aggregate in the  
usual manner.

 > aggregate(Combs[ , 3:5], list(Combs$Average), FUN=sum)
    Group.1 counts.x counts.y Average
1     -495        7        0    -495
2     -490        6        0    -490
3     -485        2        0    -485
4     -480        2        0    -480
5     -475        1        0    -475
6     -470        1        0    -470
7       10       21        0      10
8       15       42        1      15
9       20       29        2      40
10      25       26        4      50
11      30       20        9      90
... rest of output deleted.

The top and bottom rows of both tables appear to me to have no value.  
They are not really items in the sample space or the problem and their  
purpose remains a mystery.


(And ... Please do learn to include context.)