O'Reilly logo

Learning Shiny by Hernán G. Resnizky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required