In R, how to use a "null" default value for an argument of a function? -


here current code:

my.function <- function( my.arg="" ){   if(my.arg == "")     my.arg <- rnorm(10)   return( mean(my.arg) ) } 

it returns me this:

> my.function( rbinom(10, 100, 0.2) ) [1] 18.5 warning message: in if (a == "") <- rnorm(10) :   condition has length > 1 , first element used 

i tried my.arg=c(), or my.arg=0, either warning or error. , r manual doesn't on issue.

any idea? in advance!

try

my.function <- function( my.arg=null ){  if(is.null(my.arg)) ... 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -