Re: [R] problems in converting numeric to character

2018-06-08 Thread Sigbert Klinke
sprintf("%.1f", x) sprintf("%.2f", x) Am 07.06.2018 um 17:12 schrieb 刘瑞阳: 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

Re: [R] problems in converting numeric to character

2018-06-07 Thread Adrian Dușa
Does this helps? > formatC(x, digits = 1, format = "f") [1] "1.0" "2.0" "2.0" "2.1" On Thu, Jun 7, 2018 at 10:08 PM 刘瑞阳 wrote: > 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.0

Re: [R] problems in converting numeric to character

2018-06-07 Thread Jeff Newmiller
?formatC (digits, drop0trailing) ?sprintf (format %f) ?cat ?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.

[R] problems in converting numeric to character

2018-06-07 Thread 刘瑞阳
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