Matrices and Data Frames
Jim Duggan · 2024
Both matrices and data frames provide a structure to store rectangular data, which is the usual format found in spreadsheets or database tables. Typically, in a rectangular dataset, every column represents a variable, and each row contains an observation, for example, a set of values that are related (weather variables at a specific point in time). Matrices are used to store data of the same type, while data frames can store data of different types. This chapter introduces the matrix and the data frame, and shows how we can process data in these structures, using ideas from subsetting atomic vectors and lists. It explains how functionals can be applied to matrices and data frames, including the apply() functional, which can iterate over rows or columns. Two mini-cases are presented: the first shows how a matrix can be used to store information on a social network structure, and that can capture connections between individuals, and the second highlights how a processing pipeline, using R&s;s native pipe operator, can be used to process a data frame.