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

View source: R/generic.R

df2matdfR Documentation

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)

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.

Value

A data.frame

See Also

match, unique, duplicated

Examples


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


evgam documentation built on Sept. 3, 2026, 5:09 p.m.