Hi all # I have this data set and how can I assign NA?s in just one command ? And why the summary(dat) function preserves the value 9 as real. ? x <- c(1,2,3,9,4) y <- c(3,6,9,2,3) z <- c(9,9,2,2,8) w <- c(6,5,3,0,9) dat <- cbind(x,y,z,w) summary(dat) x[x==9] <- NA y[y==9] <- NA z[z==9] <- NA w[w==9] <- NA summary(dat) summary(x) summary(y) summary(z) summary(w) Thank you all, Mauricio
Mauricio Cardeal wrote:> Hi all > > # I have this data set and how can I assign NA?s in just one command ?is.na(dat[dat==9]) <- TRUE> And why the summary(dat) function preserves the value 9 as real. ? >Because you have not changed the contents of dat at all, only the contents of x,y,z, and w. Uwe Ligges> x <- c(1,2,3,9,4) > y <- c(3,6,9,2,3) > z <- c(9,9,2,2,8) > w <- c(6,5,3,0,9) > > dat <- cbind(x,y,z,w) > summary(dat) > > x[x==9] <- NA > y[y==9] <- NA > z[z==9] <- NA > w[w==9] <- NA > > summary(dat) > summary(x) > summary(y) > summary(z) > summary(w) > > Thank you all, > Mauricio > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
dat[dat==9] <- NA because the result of mean() is real and summary()'s output is a vector. ------------------------------------------------------------------- Jacques VESLOT CNRS UMR 8090 I.B.L (2?me ?tage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr ------------------------------------------------------------------- Mauricio Cardeal a ?crit :> Hi all > > # I have this data set and how can I assign NA?s in just one command ? > And why the summary(dat) function preserves the value 9 as real. ? > > x <- c(1,2,3,9,4) > y <- c(3,6,9,2,3) > z <- c(9,9,2,2,8) > w <- c(6,5,3,0,9) > > dat <- cbind(x,y,z,w) > summary(dat) > > x[x==9] <- NA > y[y==9] <- NA > z[z==9] <- NA > w[w==9] <- NA > > summary(dat) > summary(x) > summary(y) > summary(z) > summary(w) > > Thank you all, > Mauricio > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >