Re: [R] Logical function to turn missing values to 0's

2009-01-15 Thread ONKELINX, Thierry
sonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens rafamoral Verzonden: woensdag 14 januari 2009 23:32 Aan: r-help@r-project.org Onderwerp: [R] Logical function to t

Re: [R] Logical function to turn missing values to 0's

2009-01-14 Thread Jorge Ivan Velez
Dear rafamoral, Try this: x[is.na(x)]<-0 HTH, Jorge On Wed, Jan 14, 2009 at 5:32 PM, rafamoral wrote: > > I have a dataset which contains some missing values, and I need to replace > them with zeros. I tried using the following: > > x <- matrix(data=rep(c(1,2,3,NA),6), ncol=6, nrow=6) > > y <-

Re: [R] Logical function to turn missing values to 0's

2009-01-14 Thread Gustavo Carvalho
Hello rafamoral, Try this: ifelse(is.na(x),0,x) On Wed, Jan 14, 2009 at 8:32 PM, rafamoral wrote: > > I have a dataset which contains some missing values, and I need to replace > them with zeros. I tried using the following: > > x <- matrix(data=rep(c(1,2,3,NA),6), ncol=6, nrow=6) > > y <- matr

[R] Logical function to turn missing values to 0's

2009-01-14 Thread rafamoral
I have a dataset which contains some missing values, and I need to replace them with zeros. I tried using the following: x <- matrix(data=rep(c(1,2,3,NA),6), ncol=6, nrow=6) y <- matrix(data=0, ncol=ncol(x), nrow=nrow(x)) for(i in 1:nrow(x)) { for(j in 1:ncol(x)) { y[i,j] <- ifelse(x[i,j]==NA