R: 自定义函数

###################################################函数

问题:自定义函数   18.4.29

         自定义函数,其返回值是个问题,还有怎么让过程变量成为全局变量,是个问题????。。。。。。。。。。。。。this

解决方案:spa

         NA.detec <- function(x){io

           D = sum(is.na(x),na.rm = TRUE)}ast

         ZERO.detec <- function(x){function

           # D = colSums(x == 0,na.rm = TRUE)  #in colSums(x == 0, na.rm = TRUE) :'x' must be an array of at least two dimensions变量

           D = sum(x == 0,na.rm = TRUE)}扩展

 

         NA.ZERO.detec <- function(x,choice = "NA"){im

           if (choice=="NA"){call

                   D = sum(is.na(x),na.rm = TRUE)

                   print(D)

           }else if(choice=="ZERO"){

                   D = sum(x == 0,na.rm = TRUE)

                   print(D)

           }else{print("have no this method.")}

         } 

         do.call("NA.ZERO.detec",args = list(liang$leave_time,"ZERO"))  #调用函数名,后面为参数。

         #函数内部找不到某个变量时,直接在外部寻找 使用。因此不能重名。。

         #函数的最后一行的结果就是返回信息。

讨论扩展:

        

另请参阅:

相关文章
相关标签/搜索