Basic summary functions

In this section, table() and aggregate() will be covered. They are basic processing functions that come in the base package.

  • table(): This creates a contingency table with the specified vectors. Although its output is of the table type, it works similar to an array:
    sample.data <-data.frame(var1 =rep(c("Male","Female"),10), var2 =rep(c("A","B","C","D")))
    example.table<-table(sample.data$var1, sample.data$var2)
    example.table
    ##         
    ##          A B C D
    ##   Female 0 5 0 5
    ##   Male   5 0 5 0
    example.table[2,2]
    ## [1] 0
    

    The output of table() can be indexed in the same way as an array.

  • aggregate(): This performs one or more functions over a vector split by a factor variable. aggregate() has basically two ways of usage:
    • With vectors: One or more ...

Get Learning Shiny now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.