[R] remove pairs of missing values

Marc Schwartz MSchwartz at medanalytics.com
Wed Mar 17 19:15:35 CET 2004


On Wed, 2004-03-17 at 11:42, klea lambrou wrote:
>    hello R-users.I really need your help on these one.i have two vectors
>    x and y of equal length.y contains missing values,so i need to remove
>    them.i know how to do that for y but i also need the corresponding x
>    value to be removed too.i cannot find or at least think of a command
>    which will do this.can you please help me?


Use complete.cases():

x <- c(1:6)
y <- c(1, 2, NA, 4, 5, NA)
z <- cbind(x, y)

> z
     x  y
[1,] 1  1
[2,] 2  2
[3,] 3 NA
[4,] 4  4
[5,] 5  5
[6,] 6 NA

> z[complete.cases(z), ]
     x y
[1,] 1 1
[2,] 2 2
[3,] 4 4
[4,] 5 5

See ?complete.cases for more information.

HTH,

Marc Schwartz




More information about the R-help mailing list