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?
miss <- is.na(y) y.good <- y[!miss] x.good <- x[!miss] HTH, Andy> From: klea lambrou> > 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? > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
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)> zx 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
not.ok <- is.na(y) y.new <- y[! not.ok] x.new <- x[! not.ok] should work. jan On Wed, 17 Mar 2004, 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? > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- +----------------------------------------- Jan Goebel j g o e b e l @ d i w . d e DIW Berlin German Socio-Economic Panel Study (GSOEP) K?nigin-Luise-Str. 5 D-14195 Berlin -- Germany -- phone: 49 30 89789-377 +-----------------------------------------
I think the easiest way is using na.omit function which omits pairs of data Look at the following example: > x <- c(0,1,2,3,4,5) > y <- c(NA,2, 3, 5, NA, 6) > data.1 <- data.frame(x,y) > data.1 x y 1 0 NA 2 1 2 3 2 3 4 3 5 5 4 NA 6 5 6 > new.data <- na.omit(data.1) > new.data x y 2 1 2 3 2 3 4 3 5 6 5 6 > -- Jose A. Hernandez Ph.D. Candidate Precision Agriculture Center Department of Soil, Water, and Climate University of Minnesota 1991 Upper Buford Circle St. Paul, MN 55108 Ph. (612) 625-0445, Fax. (612) 625-2208