On 28-Aug-11 15:37:06, Ram H. Sharma wrote: > Dear R users: > Sorry for this simple question: > > I am writing a function where I would need to pickup p values > and make -log10 of it. > > The p values are from an anova output and sometime it can > yield me 0. > > -log10 (0) > > [1] Inf > > I can not replace Inf with 0, which not case here. > > > This is restricting me to go further in the function and out > me the error. > You help is highly appreciated. > > Thanks; > -- > Ram H
You cannot do anything about -log10(0) except to accept "Inf". However, since log10() switches from a numeric answer to "Inf" between 1/(10^308)) and 1/(10^309), one possibility for reporting such a result is to report "> 308): -log10(1/(10^307)) # [1] 307 -log10(1/(10^308)) # [1] 308 -log10(1/(10^309)) # [1] Inf Note that the above forces R to compute the number before applying log10() to it. You can get a bit further with: -log10(1e-322) # [1] 322.0052 -log10(1e-323) # [1] 323.0052 -log10(1e-324) # [1] Inf -log10(1e-325) # [1] Inf which may have something to do with R parsing the expression before applying log10() to it (I don;t know). However, since the p-value returned from an ANOVA will be a number rather than an expression, the first set of results is probably more relevant to your case. Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.hard...@wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 28-Aug-11 Time: 17:12:34 ------------------------------ XFMail ------------------------------ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.