[R] as.character ()

jim holtman jholtman at gmail.com
Mon Mar 31 23:48:25 CEST 2008


Is this what you want:

> x=c(2.00,1.20,5.00,6.56)
> sprintf("%.2f", x)
[1] "2.00" "1.20" "5.00" "6.56"


On Mon, Mar 31, 2008 at 4:45 PM, benlafleche <benlafleche at gmail.com> wrote:
> Hello,
>
> I'm trying to tranform a numeric vector into a character vector.
>
>  > x=c(2.00,1.20,5.00,6.56)
>  > y= as.character(x)
>  > y
> [1] "2"    "1.2"  "5"    "6.56"
>
> What I want is :
>
> [1] "2.00"    "1.20"  "5.00"    "6.56"
>
>
> Does someone know how to do this please ?
>
>
> Benoit Bruneau
>
> ______________________________________________
> R-help at 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list