I have a dataframe with variables, say a,b,c,d
dat <- data.frame(a=runif(1e5), b=runif(1e5), c=runif(1e5), d=runif(1e5))
and would like to g
Since model.matrix complains for factors with just one level, you alternatively might want to use stats::terms
model.matrix
stats::terms
labels(terms(~.^2, data = iris[, 1:3])) # [1] "Sepal.Length" "Sepal.Width" "Petal.Length" # [4] "Sepal.Length:Sepal.Width" "Sepal.Length:Petal.Length" "Sepal.Width:Petal.Length"