Hi All,



I have some data where I am doing fairly simple calculations, nothing more
than adding, subtracting, multiplying and dividing.



I’m running into a problem when I divide one variable by another and when
they’re both 0 I get NaN. I realize that if you divide a non-zero by 0 then
you get Inf, which is, of course, correct.  But in my case I never get Inf,
just NaN because of the structure of my dataset.



Here’s a dumb example:



var1 <- c(0, 500, 5379, 0, 1500, 1750)

var2 <- c(0, 36, 100, 0, 10, 5)



var1/var2





I realize the NaNs are logical, but for my purposes this should just be 0
because I am calculating expenditures and if you spent no money in one
sub-area and none in the whole area then you don't have an expenditure at
all, so it should be 0.  And since R doesn't like adding NA's or NaN's to
anything, I'd rather just have this be 0 so that my future calculations,
such as adding up expenditure, is simple.


Is there an easy way to avoid the NaN's, something a non-programmer (ie,
the person I am handing this code off to) would understand?


Thanks,


Jen

	[[alternative HTML version deleted]]

