[R] output without quotes

David Winsemius dwinsemius at comcast.net
Sat Jul 10 01:49:54 CEST 2010


On Jul 9, 2010, at 7:19 PM, Erik Iverson wrote:

> AC Del Re wrote:
>> Hi David,
>> I don't have the function in order yet but the names will be going  
>> into the
>> formula, e.g.,
>> in body of function:
>>      {
>>  ...etc
>>  out <- lm( y ~ TEMP)  # where TEMP = mod1+mod2 (from previous post)
>>  return(out)
>> }
>
> So why not just pass the formula to the function?

Exactly.

?formula

mod1 <- rnorm(20, 10, 2)
mod2 <- rnorm(20, 5, 1); y=mod1+mod2+rnorm(20)
dat <- data.frame(y, mod1, mod2)

# collapsing the colnames to 'mod1+mod2'
temp <- paste(names(dat), collapse="+")
form <- formula(paste("y ~",temp))

newfunc <- function(form, datfrm ) lm(form, data=datfrm)

newfunc(form=form, datfrm=dat)

### output #######
Call:
lm(formula = form, data = datfrm)

Coefficients:
(Intercept)         mod1         mod2
      -2.472        1.157        1.148

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list