贊助

Donate

搜尋此網誌

贊助本站

Donate

2018年4月3日 星期二

R: Usage of NULL

R: Usage of NULL

The first method:

min=function(x){
  s=NULL
  for (i in x){
    if (is.null(s))  s=i  else if (i<s) s=i
  }
  return (s)
}


min(c(3,6,3,2))
## [1] 2

The second method:

Be careful about or logical, using ‘||’ not ‘|’

min2=function(x){
  s=NULL
  for (i in x){
    if (is.null(s) || i<s) {s=i}
  }
    return (s)}


min2(c(13,6,5,21))
## [1] 5

沒有留言:

張貼留言

C3 plot package

R:C3 plot Peter Lin 2018-06-02 library (ggplot2) x=c( "vs" , "cyl" , "carb" , "gear" ) for...

Donate-2

Donate-2