Re: [R] as.character ()

From: <Bill.Venables_at_csiro.au>
Date: Tue, 01 Apr 2008 14:29:10 +1000

An older alternative uses format()

> x <- c(2.00, 1.20, 5.00, 6.56)
> format(x)
[1] "2.00" "1.20" "5.00" "6.56"

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of jim holtman
Sent: Tuesday, 1 April 2008 7:48 AM
To: benlafleche
Cc: R-help_at_r-project.org
Subject: Re: [R] as.character ()

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?

______________________________________________
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.

______________________________________________
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.
Received on Tue 01 Apr 2008 - 04:38:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Apr 2008 - 05:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive