-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of Sarah Goslee
Sent: Wednesday, September 26, 2012 1:26 PM
To: K. Brand
Cc: r-help@r-project.org
Subject: Re: [R] specifying arguments in functions and calling
functions, within functions
Hi,
You have some
Esteemed R UseRs,
Regarding specifying arguments in functions and calling functions
within functions:
## beginning ##
## some data
ex - rnorm(10)
ex[5] - NA
## example function
Scale - function(x, method=c(mean, median)) {
scl - method
scl(x)
}
## both return NA
Scale(ex, method=median)
Hi,
You have some basic confusion here, and a problem likely caused by an
object named scl that exists in your global environment.
On Wed, Sep 26, 2012 at 11:56 AM, K. Brand k.br...@erasmusmc.nl wrote:
Esteemed R UseRs,
Regarding specifying arguments in functions and calling functions
within
Hello,
You define a 2nd version of Scale with the dots argument but do not use it.
Scale2 - function(x, method=c(mean, median),...) {
scl - match.fun(method)
scl(x, ...) # Here!
}
Scale2(ex, method=median, na.rm=TRUE) # both return
Scale2(ex, method=median, na.rm=TRUE) # the median
Goslee
Sent: Wednesday, September 26, 2012 1:26 PM
To: K. Brand
Cc: r-help@r-project.org
Subject: Re: [R] specifying arguments in functions and calling
functions, within functions
Hi,
You have some basic confusion here, and a problem likely caused by an
object named scl that exists in your
5 matches
Mail list logo