[R] strange behavior in base::as.double

Iris Simmons |kw@|mmo @end|ng |rom gm@||@com
Wed May 1 21:32:35 CEST 2024


This happens because "123e" looks like exponential form. This string has no
exponent, so it gets treated as 0 exponent.

If you're interested in converting hex numbers, append 0x:

as.numeric("0x123a")

or use strtoi:

strtoi("123a", 16)

On Wed, May 1, 2024, 15:24 Carl Witthoft <cellocgw using gmail.com> wrote:

> Hello.
> I'm running R 4.4.0 on an iMac Venture 13.5.2 .   There appears to be a bug
> in as.double().
>
> Create a string with a numeric digits followed by a single letter a thru f
> (as tho' it's base 16).
>
> for  K  in (a,b,c,d, and f ) ,  as.double( '123K') returns NA
> but as.double('123e') returns 123 -- or whatever the first digit is.
>
> Please let me know if there are additional tests I can try .
>
>
> thanks
> Carl Witthoft
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list