[R] Dividing by 0
nmarti
nate318i at yahoo.com
Thu Jul 24 15:57:20 CEST 2008
I'm trying to calculate the percent change for a time-series variable.
Basically the first several observations often look like this,
x <- c(100, 0, 0, 150, 130, 0, 0, 200, 0)
and then later in the life of the variable they're are generally no more
0's. So when I try to calculate the percent change from one observation to
the next, I end up with a lot of NA/Nan/INF, and sometimes 0's which is what
I want, in the beginning.
I know I can use x <- na.omit(x), and other forms of this, to get rid of
some of these errors. But I would rather use some kind of function that
would by defult give a 0 while dividing by zero so that I don't lose the
observation, which is what happens when I use na.omit.
I would imagine this is a common problem. I tried finding something in zoo,
but I haven't found what I'm looking for.
Any advice would be appreciated.
--
View this message in context: http://www.nabble.com/Dividing-by-0-tp18632469p18632469.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list