The isChar function used in Parse is:
isChar <- function(e, ch) identical(e, as.symbol(ch))
On Fri, Aug 24, 2018 at 10:06 PM Gabor Grothendieck
wrote:
>
> Also here is a solution that uses formula processing rather than
> string processing.
> No packages are used.
>
> Parse <- function(e) {
>
Also here is a solution that uses formula processing rather than
string processing.
No packages are used.
Parse <- function(e) {
if (length(e) == 1) {
if (is.numeric(e)) return(e)
else setNames(1, as.character(e))
} else {
if (isChar(e[[1]], "*")) {
x1 <- Recall(e[[2]])
Some string manipulation can convert the formula to a named vector such as
the one shown at the end of your post.
library(gsubfn)
# input
fo <- y ~ 2 - 1.1 * x1 + x3 - x1:x3 + 0.2 * x2:x2
pat <- "([+-])? *(\\d\\S*)? *\\*? *([[:alpha:]]\\S*)?"
ch <- format(fo[[3]])
m <- matrix(strapplyc(ch, pat)[
lsciences.mcmaster.ca/jfox/
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul
> Johnson
> Sent: Tuesday, August 21, 2018 6:46 PM
> To: R-help
> Subject: [R] looking for formula parser that allows coefficients
>
> Can
Can you point me at any packages that allow users to write a
formula with coefficients?
I want to write a data simulator that has a matrix X with lots
of columns, and then users can generate predictive models
by entering a formula that uses some of the variables, allowing
interactions, like
y ~ 2
5 matches
Mail list logo