Book Image

Learning Shiny

By : Hernan Resnizky
Book Image

Learning Shiny

By: Hernan Resnizky

Overview of this book

Table of Contents (19 chapters)
Learning Shiny
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Introducing R, RStudio, and Shiny
Index

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 vectors are passed to the x argument while one or more factor vectors are passed in the by argument. FUN is the aggregation function to be used:

      > data(iris)
      > aggregate(iris$Sepal.Length, by=list(iris$Species...