Re: [R] Help with NaN when 0 divided by 0

2012-08-01 Thread William Dunlap
essage- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Jennifer Sabatier > Sent: Wednesday, August 01, 2012 7:18 AM > To: David Winsemius > Cc: r-help@r-project.org > Subject: Re: [R] Help with NaN when 0 divided by 0 > >

Re: [R] Help with NaN when 0 divided by 0

2012-08-01 Thread Jennifer Sabatier
Hi Everyone, Thanks so much for all your suggestions! All of these worked but David's was best suited for my purposes, considering it was something happens sporadically. I don't do expenditure analyses often as I mostly do run of the mill survey analysis, but this will come in handy for the once

Re: [R] Help with NaN when 0 divided by 0

2012-07-31 Thread David Winsemius
On Jul 31, 2012, at 1:23 PM, Jennifer Sabatier wrote: 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

Re: [R] Help with NaN when 0 divided by 0

2012-07-31 Thread Sarah Goslee
Hi, Here are two possible ways to deal with it. Which is better depends on the larger context of your code. There's no right way, just whichever is more convenient. > ifelse(var2 != 0, var1/var2, 0) [1] 0.0 13.9 53.79000 0.0 150.0 350.0 > > newvar <- var1/var2 > newvar[i

Re: [R] Help with NaN when 0 divided by 0

2012-07-31 Thread Marc Schwartz
On Jul 31, 2012, at 3:23 PM, Jennifer Sabatier wrote: > 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

[R] Help with NaN when 0 divided by 0

2012-07-31 Thread Jennifer Sabatier
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