problem-4.10

problem-4.10  The data set is stored in a matrix, so we can reverse the years using indexing.
> barplot(t(dvdsales[7:1,]), beside=TRUE)
    
Using apply() on the rows, we get the yearly amounts:
> apply(dvdsales, 1, sum)
    2004     2003     2002     2001     2000     1999     1998
      NA 21994389 17089823 12706584  8498545  4019389  1089261
    1997
      NA
> apply(dvdsales, 1, function(x) sum(x,na.rm=TRUE)) # avoid NA
    2004     2003     2002     2001     2000     1999     1998
 5957387 21994389 17089823 12706584  8498545  4019389  1089261
    1997
  315136
    
Applying sum() to the columns gives the monthly sales. We do so only for years that have complete data.
> apply(dvdsales[2:6,], 2, sum)
    JAN     FEB     MAR     APR     MAY     JUN     JUL     AUG
2407354 2545896 4761189 3677919 3539725 5634658 3521254 3812934
    SEP     OCT     NOV     DEC
8362963 7551936 9323618 9169284
    
November is the big winner. (Christmas shopping?)