-5

from this example:

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

from the last run ( Error: could not find function "ic") why it give me this and how I solve this broblem with function ic

  • but is give me this `FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE ` but i want to extract all instances that contain NA – user5934339 Sep 18 '16 at 07:14
  • But I want to solve my function problem I mean (ic) – user5934339 Sep 18 '16 at 07:17
  • [Use correct R notation for creating a function](http://www.statmethods.net/management/userfunctions.html). Now the question is: What do you want `drop` to do? Why don't you want to use `complete.cases`? – Therkel Sep 18 '16 at 07:31
  • I will do it , but I want to help me to fix ic function that will give me the same result like `x[!complete.cases(x), ]` . – user5934339 Sep 18 '16 at 13:03

1 Answers1

4

I don't quite understand what your function ic is doing, including brackets and the drop bit.

If you want complete cases, the most handy way is na.omit(x) or x[complete.cases(x), ]. But since you want incomplete cases, we need x[!complete.cases(x), ].

I certainly understand what ici is doing. It is just is.na. If I were asked to start from is.na, I would use the following:

x[rowSums(is.na(x)) > 0L, ]
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248