[R] How do I fix this ?

Pete Brecknock Peter.Brecknock at bp.com
Thu Jan 27 04:55:37 CET 2011


Eric

Your problem lies in the way cumprod deals with NAs

If you look at ?cumprod you will see 
"An NA value in x causes the corresponding and following elements of the
return value to be NA"

Not sure what behaviour you want to see on encountering an NA (ignore it,
restart the cumprod process, .....). Making things easy for myself (it's
late), if you wish to simply ignore an NA the following would work

# sample data
y2=c(NA,1,2,3,4,5)

# ignore NA
ave(y2,is.na(y2),FUN=cumprod)

HTH

Pete

 

-- 
View this message in context: http://r.789695.n4.nabble.com/How-do-I-fix-this-tp3239239p3241432.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list