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

rafamoral rafa_moral2004 at yahoo.com.br
Wed Jan 14 23:32:22 CET 2009


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, 0, x[i,j])

}}

But y returns an NA matrix.
I'd appreciate any help.
-- 
View this message in context: http://www.nabble.com/Logical-function-to-turn-missing-values-to-0%27s-tp21466785p21466785.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list