Hello, Does anyone know of a function that will determine whether or not a formula object has a left hand side? I.e., can differentiate between y ~ x + z and ~ x + z Perhaps I'm overlooking the obvious... Thanks!
attr(terms(formula), "response") is 1 if the formula has a left hand side and 0 otherwise. At a lower level, you can look at length(formula): 2 means there is no LHS, 3 means there is (any other value indicates that someone made a call object that the parser would not make). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Erik Iverson > Sent: Monday, December 13, 2010 12:17 PM > To: R-help > Subject: [R] Does a formula object have a "left hand side" > > Hello, > > Does anyone know of a function that will determine whether > or not a formula object has a left hand side? > > I.e., can differentiate between > > y ~ x + z > > and > > ~ x + z > > Perhaps I'm overlooking the obvious... > > Thanks! > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Erik - Perhaps the "response" attribute of the terms() function?> formula1 = formula(y ~ x + z) > formula2 = formula(~x + z) > attr(terms(formula1),'response')[1] 1> attr(terms(formula2),'response')[1] 0 Although there may be more direct ways. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spector at stat.berkeley.edu On Mon, 13 Dec 2010, Erik Iverson wrote:> Hello, > > Does anyone know of a function that will determine whether > or not a formula object has a left hand side? > > I.e., can differentiate between > > y ~ x + z > > and > > ~ x + z > > Perhaps I'm overlooking the obvious... > > Thanks! > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >