R, replace NA with zero

How can I replace the values NAwith zero in the R zoo series? I read about na.locfand na.omit, but I think that none of them do what I need.

thank.

+3
source share
2 answers

I am not familiar with the Zoo Series, but this is how you do it with vectors. That should work.

x = c(NA,1,2,3)
x[ is.na(x) ] <- 0 
print (x)
+12
source

Use na.fill. If z- a series of zoos:

na.fill(z, fill = 0)
+3
source

Source: https://habr.com/ru/post/1765594/


All Articles