Re: [R] 0* log(0) should be zero but NaN

From: jim holtman <jholtman_at_gmail.com>
Date: Wed 12 Jul 2006 - 08:58:19 EST

> prob <- c(0.5,0.4,0.3,0.1,0.0)
> cal <- prob * log(prob,base=2)
> cal
[1] -0.5000000 -0.5287712 -0.5210897 -0.3321928 NaN
> cal[is.nan(cal)] <- 0
> cal

[1] -0.5000000 -0.5287712 -0.5210897 -0.3321928 0.0000000
>

On 7/11/06, Taka Matzmoto <sell_mirage_ne@hotmail.com> wrote:
>
> Dear R-users
>
> >prob <- c(0.5,0.4,0.3,0.1,0.0)
> >cal <- prob * log(prob,base=2)
> >cal
> [1] -0.5000000 -0.5287712 -0.5210897 -0.3321928 NaN
>
> Is there any way to change NaN to zero ?
>
> I did come up with this by applying Ripley's relpy to my previous question
>
> cal <-prob*log(pmax(prob,0.00000001),base=2)
>
> Any suggestion ?
>
> Thank you
>
> Taka
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390 (Cell)
+1 513 247 0281 (Home)

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jul 12 09:04:39 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 12 Jul 2006 - 10:17:12 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.