zoukankan      html  css  js  c++  java
  • R: 自定义函数

    ###################################################

    问题:自定义函数   18.4.29

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

    解决方案:

             NA.detec <- function(x){

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

             ZERO.detec <- function(x){

               # 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"){

               if (choice=="NA"){

                       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"))  #调用函数名,后面为参数。

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

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

    讨论扩展:

            

    另请参阅:

  • 相关阅读:
    concrete maths ch4 number theory
    Aho-Corasick algorithm
    Finding repetitions
    Suffix Automaton
    Z-function and its calculation
    mongodb安装与启动
    centos redis 集群搭建
    nginx实现热部署(平滑升级)
    nacos集群部署安装
    springboot+zookeeper+dubbo整合
  • 原文地址:https://www.cnblogs.com/li-20151130/p/9038408.html
Copyright © 2011-2022 走看看