skan
skan

Reputation: 7720

R, Substitute NAs by zero

How can I substitute NA values by zero in a R zoo series? I've been reading about na.locf and na.omit but I think none of them do what I need.

thanks.

Upvotes: 4

Views: 3349

Answers (2)

G. Grothendieck
G. Grothendieck

Reputation: 269526

Use na.fill. If z is the zoo series:

na.fill(z, fill = 0)

Upvotes: 3

st0le
st0le

Reputation: 33545

I'm not familiar with the Zoo Series but this is how you do it with vectors. This Should work.

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

Upvotes: 13

Related Questions