[R] problems in converting numeric to character

刘瑞阳
Thu, 07 Jun 2018 15:12:27 -0000

Hi,
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:

x<-c(1.0,2.0,2.00,2.1)
I want to convert them to characters so that the out put would be
c(?1.0?,?2.0?,?2.00?,?2.1?).

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!

Sincerely,

Ruiyang Liu