Division by 0 in r, avoid NaN -


i have code here:

d$icer <- d$delta_cost/d$delta_ly 

i each row, in matrix in r, now, first row has values of delta_cost , delta_ly = 0, icer 0/0 , gives me value nan.

how can modify 0 instead of nan?

you can use ifelse:

d$icer <- ifelse(!d$delta_cost, 0, d$delta_cost / d$delta_ly) 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -