Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

[R] Determining response variable in a formula

David Kane

2005-07-12

Replies:

I have a formula from which I want to deduce the name of the response
variable. One way of doing so is as follows:

> my.form <- as.formula("y ~ x + z")
> all.vars(my.form)[1]
[1] "y"
>

Is there a better way and/or preferrred method of determining "y" from
my.form than this one? In messing around with terms, I came up with:

> all.vars(terms(my.form))[attr(terms(my.form), "response")]
[1] "y"
>

But that seems too ugly to be best.

Thanks,

Dave Kane

> R.version
     _          
platform i686-pc-linux-gnu
arch   i686        
os     linux-gnu    
system  i686, linux-gnu
status            
major   2          
minor   1.0        
year   2005        
month   04          
day    18          
language R          
>

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
©2008 r-help.com - Jax Systems, LLC, U.S.A.