Learn R Programming

evgam (version 1.0.2)

df2matdf: Convert a response vector in a data frame to a matrix

Description

Convert a response vector in a data frame to a matrix

Usage

df2matdf(x, formula)

Value

A data.frame

Arguments

x

a data frame

formula

a formula

Details

This function identifies repeated combinations of explanatory variables in a mgcv formula and then creates a \(n \times m\) matrix response variable in which each row corresponds to one of \(n\) unique explanatory variable combinations and each column to one of \(m\) replicates with the combination. Here \(m\) is the maximum number of replicates for an explanatory variable combination; rows of the matrix are padded with NAs at the end where there are fewer than \(m\) replicates.

See Also

Examples

Run this code

df0 <- expand.grid(x = 1:2, y = 3:4)
df1 <- rbind(df0, df0)
df1$z <- runif(nrow(df1))
df2matdf(df1, z ~ x + y)

Run the code above in your browser using DataLab