Michael Gruenstaeudl - 3 months ago 9

R Question

Function

`constrain`

`formulae <- list(lambda1 ~ lambda0, mu1 ~ mu0, q10 ~ q01)`

constrain(lik, formulae=formulae)

I would like to pass these formulae via a decision tree and concatenate them as needed.

`f1 <- "lambda1 ~ lambda0"`

f2 <- "mu1 ~ mu0"

f3 <- "q10 ~ q01"

How do I arrive at the above-shown list

`formulae`

Unsuccessful attempt:

`formulae <- as.formula(paste(f1,f2,f3, collapse=","))`

I do not know the precise number of respective formulae

`f1`

`f2`

`f3`

`formulae`

Answer

You can use:

```
formulae = list(as.formula(f1),as.formula(f2),as.formula(f3))
```

If you originally have all string formulae in a vector, say `f <- c(f1, f2, f3)`

, you may use

```
lapply(f, as.formula)
```