[R] quickly extract response from formula

Andreas Leha andreas.leha at med.uni-goettingen.de
Fri Nov 1 22:50:19 CET 2013


Hi David,

thanks for your quick answer!

David Winsemius <dwinsemius at comcast.net> writes:

> On Oct 31, 2013, at 1:27 PM, Andreas Leha wrote:
>
>> Hi all,
>> 
>> what is the recommended way to quickly (and without much burden on the
>> memory) extract the response from a formula?
>
> If you want its expression value its just form[[2]]
>
> If you wnat it evaluated in the environment of a dataframe then this should be fairly efficient:
>
> x <- stats::runif(20)
> y <- stats::runif(20)
> dfrm <- data.frame(x=x,y=y)
> extractResponse <- function(frm, dat) { resp <- frm[[2]]; print(resp) # that's optional
>                                          fdat <- eval(resp,
>                                          envir=dat); return(fdat) }

This is what I'll be using.  Thanks again!

[...]

Regards,
Andreas



More information about the R-help mailing list