Re: [R] sprintf()

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 09 Jun 2008 13:16:53 -0400

Here is one way of getting the digits:

> x <- sprintf("%E", 0.000004)
> x

[1] "4.000000E-06"
> gsub("([[:digit:]]+$)", substr("0000\\1",nchar("\\1")+1,nchar("\\1")+4<file://1%22)+1,nchar(%22//1%22)+4>),
x, perl=TRUE)
[1] "4.000000E-0006"
>

On Mon, Jun 9, 2008 at 12:56 PM, jim holtman <jholtman_at_gmail.com> wrote:

> But be careful if your number does not contain only 0:
>
> > sprintf("%E00", pi*1000)
> [1] "3.141593E+0300"
> > sprintf("%E", pi*1000)
> [1] "3.141593E+03"
>
>
> On Mon, Jun 9, 2008 at 12:42 PM, Paulo Cardoso <pecardoso_at_netcabo.pt>
> wrote:
>
>> Yes works,
>>
>> Thank you Henrique.
>>
>> I'm so basic with R!
>>
>> Paulo
>>
>>
>>
>> From: Henrique Dallazuanna [mailto:wwwhsd_at_gmail.com]
>> Sent: segunda-feira, 9 de Junho de 2008 17:37
>> To: Paulo Cardoso
>> Cc: r-help_at_r-project.org
>> Subject: Re: [R] sprintf()
>>
>>
>>
>> Try:
>>
>> sprintf("%E00", pi)
>>
>> On Mon, Jun 9, 2008 at 1:28 PM, Paulo Cardoso <pecardoso_at_netcabo.pt>
>> wrote:
>>
>> Hi,
>>
>> I'm not being able to represent the result of sprintf("%E", pi)
>> [1] "3.141593E+00"
>>
>> Into this:
>> "3.141593E+0000"
>>
>> Thanks in advance
>>
>> Paulo
>>
>> ______________________________________________
>> 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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>> No virus found in this incoming message.
>> Checked by AVG.
>>
>> 11:17
>>
>>
>> [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> 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<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?

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

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]


______________________________________________ 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 Mon 09 Jun 2008 - 18:13:29 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 Mon 09 Jun 2008 - 18:30:41 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