formatC(x, width=8, format="f",
drop0trailing=TRUE,flag="0"),
trunc(x) )
sapply(VALUES,form3)
[1] "123456789" "12345678" "1234567.9" "123456.89" "12345.789" "1234.6789&quo
I think the following code provides output that Dennis wants as well
as gets rid of the white space David mentioned.
digitTruncation <- function(x)
{
ifelse(x>10^7, gsub("(\\d)[.].*", "\\1", x), ifelse(x<1, formatC(x, digits=3,
f
David Winsemius wrote
>
> I didn't get the same results as requested with a wider variety of
> tests using those formatting methods. Here's what I could offer:
>
> form3 <- function (x) switch(findInterval(x, c( 0, 1, 10^7, Inf)),
> format(x, digits=3),
ot;%.3f",x))
)
fun1(488.85)
#[1] "00488.85"
fun1(0.1233555)
#[1] "0.123"
Using the vector of long 5's
> sapply(tx, fun1)
[1] "0.556" "00055.56""556"
fun1(VALUES)
# [1] "123456789" "12
" "123456.89" "12345.79"
#[6] "01234.68" "00123.57" "00012.46" "1.35" "0.123"
#[11] "0.012" "0.001"
A.K.
- Original Message -
From: Dennis Fisher
To: r-h...@stat.
Colleagues
R 2.15.1
OS X
I have a lengthy script that generates a positive number that I display in a
graphic using text. The range of possible values is quite large and I am
looking for an efficient means to format.
1. If the number is large (e.g., > 10^7), I want to display only t
sign after the numbers though. It's not a problem to format a
regular 2D plot with percents but I still can't figure it out with
the persp function.
Steve
--- On Fri, 6/12/09, David Winsemius wrote:
From: David Winsemius
Subject: Re: [R] formatting numbers along axes as percen
Have you considered multiplying all values by 100?
On Jun 12, 2009, at 7:56 PM, Stephen Samaha wrote:
Hello, I'm producing a 3D plot using the persp function. All my
values for X, Y, and Z are decimals ranging from 0 to 1. I'd like to
be able format the three axes so that the tick values ar
Hello, I'm producing a 3D plot using the persp function. All my values for X,
Y, and Z are decimals ranging from 0 to 1. I'd like to be able format the three
axes so that the tick values are 0% 20% 40%, etc... instead of just being 0 .2
.4. Does anyone know how to do this?
Many thanks,
Steve
baptiste auguie wrote:
> sprintf("%04.f", 2)
>
makes no sense to use the float specifier for ints here; besides, it's
slower:
x = 1:10^5
library(rbenchmark)
benchmark(columns=c('test', 'elapsed'), replications=100,
sprintf('%05d', x),
sprintf('%05.f', x))
#
Hi, try this
A <- c(1:1000)
A <- paste ("000",A,sep="")
substr (A,nchar(A)-3,nchar(A))
Best regards,
Andris Jankevics
On Mon, Apr 27, 2009 at 12:35 PM, Mario dos Reis wrote:
> I've been trough the R documentation for about half an hour and it's not
> clear to me how to do this:
>
> I need to
sprintf("%04.f", 2)
sapply(sample(1:1000,4), function(ii) sprintf("%04.f",ii))
?sprintf
HTH,
baptiste
On 27 Apr 2009, at 11:35, Mario dos Reis wrote:
I've been trough the R documentation for about half an hour and it's
not
clear to me how to do this:
I need to format to character a seri
Mario dos Reis wrote:
> I've been trough the R documentation for about half an hour and it's
> not clear to me how to do this:
>
> I need to format to character a series of integers from 1 to 1000, and
> I like them to look like
>
> "0001" "0002", "0059", "0123" and so on. Padded with zeroes to hav
I've been trough the R documentation for about half an hour and it's not
clear to me how to do this:
I need to format to character a series of integers from 1 to 1000, and I
like them to look like
"0001" "0002", "0059", "0123" and so on. Padded with zeroes to have four
digits.
Cheers!
Mari
14 matches
Mail list logo