+1 vote
2 views
in R Programming by (3.4k points)
edited by

How to replace the values of NA with zeros in some column and data frame I have?

1 Answer

0 votes
by (46.1k points)
edited by

You can also use norm package as it has a lot of nice features for the missing data analysis and there’s no need to use apply .

For Reference check the following example:

> m <- matrix(sample(c(NA, 1:2), 100, replace = TRUE), 2)

> d <- as.data.frame(m)

 V1 V2 V3 V4 V5 V6 V7 V8 V9 V10

1  4  3 NA  3  7  6  6 10  6   5

2  9  8  9  5 10  NA 2  1  7   2

> d[is.na(d)] <- 0

> d

  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10

1   4  3  0  3  7  6  6 10  6   5

2   9  8  9  5 10  0  2  1  7   2

Comment for doubts. Cheers.

Related questions

+3 votes
1 answer
asked May 29, 2019 in R Programming by Anvi (10.2k points)
+1 vote
1 answer
+1 vote
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...