Polychronis Kostoulas
2018-Apr-26 13:46 UTC
[R] How to define mutualy exclusive parameters of a function
Dear All, apologies if this is basic: I am writing a function: fb<-function(mean, median, mode, a, b=0.95, lower=F) {....} The arguments mean, median and mode are mutually exclusive (i.e. the user should define only one of these). How do I code this within the function? Thanks, Pol [[alternative HTML version deleted]]
Eric Berger
2018-Apr-26 14:10 UTC
[R] How to define mutualy exclusive parameters of a function
Hi Pol, Here is one way: fb <- function(mean=NULL, median=NULL, mode=NULL, a, b=0.95, lower=F) { stopifnot ( (is.null(mean) + is.null(median) + is.null(mode)) == 2 ) etc... } HTH, Eric On Thu, Apr 26, 2018 at 4:46 PM, Polychronis Kostoulas < polychronis.kostoulas at gmail.com> wrote:> Dear All, > apologies if this is basic: I am writing a function: > > fb<-function(mean, median, mode, a, b=0.95, lower=F) > {....} > > The arguments mean, median and mode are mutually exclusive (i.e. the user > should define only one of these). How do I code this within the function? > > Thanks, > Pol > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
Berry, Charles
2018-Apr-26 16:42 UTC
[R] How to define mutualy exclusive parameters of a function
> On Apr 26, 2018, at 6:46 AM, Polychronis Kostoulas <polychronis.kostoulas at gmail.com> wrote: > > Dear All, > apologies if this is basic: I am writing a function: > > fb<-function(mean, median, mode, a, b=0.95, lower=F) > {....} > > The arguments mean, median and mode are mutually exclusive (i.e. the user > should define only one of these). How do I code this within the function? >See ?missing HTH, Chuck
Rui Barradas
2018-Apr-26 16:45 UTC
[R] How to define mutualy exclusive parameters of a function
Hello, Inline. On 4/26/2018 5:42 PM, Berry, Charles wrote:> > >> On Apr 26, 2018, at 6:46 AM, Polychronis Kostoulas <polychronis.kostoulas at gmail.com> wrote: >> >> Dear All, >> apologies if this is basic: I am writing a function: >> >> fb<-function(mean, median, mode, a, b=0.95, lower=F) >> {....} >> >> The arguments mean, median and mode are mutually exclusive (i.e. the user >> should define only one of these). How do I code this within the function? >> > > See > > ?missingSee also the first example in help("switch") Hope this helps, Rui Barradas> > HTH, > > Chuck > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >