[R] within()

From: Timothy Bates <timothy.c.bates_at_gmail.com>
Date: Thu, 19 May 2011 14:32:29 +0100

The most interesting thing in this thread for me was "within()" - that is what I want 99% of the time, but I had only ever heard of with()

A real boon! Thanks Bill V!

The help for within gives this example for with(), which seems unnecessary, as glm supports data=

with(anorexia, {

    anorex.1 <- glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian)     summary(anorex.1)

especially when this is easier to read:
  m <- glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian, data=anorexia)   summary(m)

The Rd file also has (just?) one example for within… I suggest deleting the anorexia example so the within example comes first, and perhaps supplementing with

## Not run:
# More advanced example of usage (not run)

model1  <- glm.nb(Cells ~ Cryogel*Day, data = myData)
myData2 <- within(myData, Cryogel <- relevel(Cryogel, ref = "2"))
model2  <- update(model1, data = myData1) 
## End(Not run)

Also, the help page for transform does not back link to within… That would be helpful. It also uses an example with attach, which might encourage less good habits.

Best wishes, and thanks,
PS : How does one best contribute to help files? PPS: If R was to go to google summer of code, apart from helpful help, my wishlist would prioritise standardising all common functions to (where possible)

1. Have a formula interface
2. Support “data=“
3. Use a uniform na handling, with examples

Diverse NA behavior catches most of our students out (now all three departments of our school using R exclusively at the PG level) NA behaviour can be

na.rm=     as in rowMeans(na.rm=T))
use=         as in an cor(use=“every”)   # with well documented effects in ?cor(), and all legal options  shown (everything|all.obs|complete.obs|na.or.complete|pairwise.complete.obs)
na.action= as in t.test(na.action=“na.omit”) # with no examples in ?t.test, nor a list of legal values

Likewise it would help reduce confusion when plot(~Source, data=Df) # works
# but

boxplot(~Source, data=Df)
# Error in boxplot.formula(~Source, data = Df) :
# 'formula' missing or incorrect

The formula isn’t missing or illformed, it’s that boxplot requires formulae to have something on the left hand side.

best, t

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. Received on Thu 19 May 2011 - 13:34:18 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 May 2011 - 15:40:07 GMT.

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

list of date sections of archive