Re: [R] Splitting the left and right hand terms of a formula

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 15 Jul 2006 - 04:27:57 EST

Try this:

> all.vars(update(a.formula, .~0))

[1] "x"

> all.vars(update(a.formula, 0~.))

[1] "y" "z"

On 7/14/06, Daniel Gerlanc <dgerlanc@gmail.com> wrote:
> Let's say I have the following formula:
>
> a.formula <- x ~ y + z
>
> I want to extract the left and right-hand sides of the function so
> that I have two character vectors like the ones you would create using
> the following assignments:
>
> left.hand.side <- "x"
> right.hand.side <- c("y", "z")
>
> One way to do this follows:
>
> left.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[1])
> right.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[-1])
>
> Is there a better or cleaner way to do this?
>
> Thanks!
>
> Daniel Gerlanc
> Williams College '07
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
>
https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jul 15 04:32:17 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 15 Jul 2006 - 06:15:51 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.