2016-09-18 49 views
-5

从这个例子:提取不完整的情况下,从数据集R中

## x 
    ## v1 v2 v3 
    ##1 90 55 NA 
    ##2 NA 45 8 
    ##3 85 NA 5 
    ##4 NA 33 7 
    ##5 55 30 4 
    ##6 60 20 3 
    ##7 75 15 2 
    ##8 80 23 6 
    # ici is where Incomplete case indicator 

    ici=(function (x) 
    return(is.na(x))) 

    ici(x) 
      v1 v2 v3 
    ## [1,] FALSE FALSE TRUE 
    ## [2,] TRUE FALSE FALSE 
    ## [3,] FALSE TRUE FALSE 
    ## [4,] TRUE FALSE FALSE 
    ## [5,] FALSE FALSE FALSE 
    ## [6,] FALSE FALSE FALSE 
    ## [7,] FALSE FALSE FALSE 
    ## [8,] FALSE FALSE FALSE 

    # Extracts incomplete cases from a data set 

    ic=(function (x, drop) 
    return(x[ici(x)]))(x, drop) 

    ic(x) 
    ## Error: could not find function "ic" 

从上次运行(错误:无法找到函数“IC”)为什么给我这个,我该如何解决这个broblem与功能ic

+0

但给我这个'假假假假真真真真的'但是我想提取包含NA – user5934339

+0

所有实例但我想解决我的功能问题我的意思是(ic) – user5934339

+0

[使用正确的R表示法来创建函数](http://www.statmethods.net/management/userfunctions.html)。现在的问题是:你想要“放下”做什么?你为什么不想使用'complete.cases'? – Therkel

回答

3

我不太明白你的功能ic在做什么,包括括号和drop位。

如果您想要完整的案例,最方便的方法是na.omit(x)x[complete.cases(x), ]。但既然你想要不完整的案例,我们需要x[!complete.cases(x), ]

我当然明白ici在做什么。它只是is.na。如果我被要求从is.na开始,我将使用以下命令:

x[rowSums(is.na(x)) > 0L, ] 
相关问题