r-formula
Formula with dynamic number of variables
See ?as.formula, e.g.: factors <- c(“factor1”, “factor2”) as.formula(paste(“y~”, paste(factors, collapse=”+”))) # y ~ factor1 + factor2 where factors is a character vector containing the names of the factors you want to use in the model. This you can paste into an lm model, e.g.: set.seed(0) y <- rnorm(100) factor1 <- rep(1:2, each=50) factor2 <- rep(3:4, … Read more
Use of ~ (tilde) in R programming Language
The thing on the right of <- is a formula object. It is often used to denote a statistical model, where the thing on the left of the ~ is the response and the things on the right of the ~ are the explanatory variables. So in English you’d say something like “Species depends on … Read more