Learn R Programming

SciencesPo (version 1.3.6)

rectangularize: Make a data.frame Rectangular by fill in missing records

Description

rectangularize produces a complete rectangularization table by adding observations with missing data so that all combinations (interactions) of the specified variables exist.

Usage

rectangularize(x, by, fill = NA)

Arguments

x
a data frame.
by
a vector of at least 2 variables from the data frame. If missing all variables in the data frame will be used.
fill
the value used to fill in, default is fill = 0.

Value

  • a data object of the same class as x.

encoding

UTF-8

Examples

Run this code
data <- data.frame(sex=c("female","male","male"),
race = c("black","black","white"), y = c(.5,.4,.1), x = c(32,40,53))

rectangularize(data, by=c(sex,race))

rectangularize(data, by=c(sex,race), fill=0)

Run the code above in your browser using DataLab