Chapter 2: Working with Categorical Data


Creating and manipulating categorical data sets requires some skills and techniques in R beyond those ordinarily used for quantitative data. This chapter illustrates these for the main formats for categorical data: case form, frequency form and table form.


2.1. Working with R data: vectors, matrices, arrays, and data frames
2.2. Forms of categorical data: case form, frequency form, and table form
2.3. Ordered factors and reordered tables
2.4. Generating tables: table and xtabs
2.5. Printing tables: structable and ftable
2.6. Subsetting data
2.7. Collapsing tables
2.8. Converting among frequency tables and data frames
2.9. A complex example: TV viewing data
2.10. Lab exercises

Selected figures

view R code

Figure 2.1

Principal data structures and data types in R. Colors represent different data types: numeric, character, and logical. datatypes diagram

Table 2.1

Tools for converting among different forms for categorical data. converting among data types