[R] problems in converting numeric to character

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Thu Jun 7 21:40:40 CEST 2018

?formatC (digits, drop0trailing)
?sprintf (format %f)
?options (digits)

You appear to be confusing source code formatting with output formatting. The internal representation of a numeric value has no notion of the number of decimals that were used to enter it into memory from source code. By the time you (or R) decide to re-convert it to a visual representation (characters), all trace of the original representation has been forgotten, so you have to be explicit about your output format, or R will make assumptions.

On June 7, 2018 8:12:27 AM PDT, "刘瑞阳" <ruiyangliu94 using gmail.com> wrote:
>I am having trouble converting numeric to characters in the format I
>desire. To be more specific, I have a number of numeric as follows:
>I want to convert them to characters so that the out put would be
>However, I used as.character(x) and the output is:
>"1"   "2"   "2"   “2.1"
>The decimals are removed if the numeric ends with “.0”. Is there a way
>to circumvent this problem?
>Thanks very much!
>Ruiyang Liu
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

Sent from my phone. Please excuse my brevity.

More information about the R-help mailing list