[R] How to create functions with new "defaults"?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Sep 2 12:42:55 CEST 2008
On Tue, 2 Sep 2008, David Hajage wrote:
> I can't test it right now, but is this ok ?
>
> t.test.new <- function(x, y = NULL,
> alternative = c("two.sided", "less", "greater"),
> mu = 0, paired = TRUE, var.equal = FALSE,
> conf.level = 0.95, ...) {
> t.test(x, y,
> alternative,
> mu, paired, var.equal,
> conf.level, ...)
> }
You should name the arguments in the t.test call for safety. But just
t.test.new <- function(..., paired = TRUE) t.test(..., paired=paired)
is all you need, and for example allows formulae to be used.
>
> 2008/9/2 Prabhanjan Tattar <prabhanjannt at gmail.com>
>
>> Hi R!
>> I attempt to clear my question through this example. We know that the
>> default functions for "t.test" is
>> t.test(x, y = NULL,
>> alternative = c("two.sided", "less", "greater"),
>> mu = 0, paired = FALSE, var.equal = FALSE,
>> conf.level = 0.95, ...)
>> Suppose, I want to create a new function where "paired=TRUE". What is the
>> simpler way of creating such functions? I did try, but without much
>> success.
>> Thanks in advance
>> --
>> Prabhanjan N. Tattar
>> Lead Statistician
>> CustomerXPS
>> Bangalore
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list