| df2matdf | R Documentation |
Convert a response vector in a data frame to a matrix
df2matdf(x, formula)
x |
a data frame |
formula |
a formula |
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.
A data.frame
match, unique, duplicated
df0 <- expand.grid(x = 1:2, y = 3:4)
df1 <- rbind(df0, df0)
df1$z <- runif(nrow(df1))
df2matdf(df1, z ~ x + y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.