Data Structures and Wrangling

Smruti Bulsari, Kiran Pandya · 2026

This chapter discusses data structures, different formats in which data are stored, in R. Each format is an object type and has a name. We discuss vectors, factors, matrices, arrays, lists and dataframes. With a section dedicated to each object/format type, we begin with the structure of each of the objects, and then explain, with examples, how data stored in each of these objects can be indexed, subset, sampled and bootstrapped. Some objects like numeric vectors and matrices allow arithmetic operations to be undertaken on the individual elements, which we discuss with relevant examples. Matrices also allow matrix-specific operations like matrix multiplication and transpose. We discuss that too, with examples. Lists and arrays can have named elements, and we discuss the commands to name them. Each section ends with the limitation of that data structure. Some mathematical and statistical operations are sensitive to missing values/observations. We discuss the concept of missing values and dealing with missing values, including omission and imputation. The chapter has an appendix enlisting commands and its simple explanation for vector transformation, statistical functions that can be used with vectors, generating sequences, undertaking matrix operations and some built-in constants in R.

Read the paper · More papers on PaperTik