Skip to content
Prev 327692 / 398502 Next

'format' behaviour in a 'apply' call depending on 'options(digits = K)'

Hi,
Try using trim=TRUE, in ?format()
options(digits=4)

df2 <- data.frame(x = rnorm(110000), y = rnorm(110000), id = 1:110000)
?df2$id2 <- apply(df2, 1, function(dfi) format(dfi["id"], trim=TRUE,scientific = FALSE)) 
? df2$id2[99990:100010] 
# [1] "99990"? "99991"? "99992"? "99993"? "99994"? "99995"? "99996"? "99997" 
# [9] "99998"? "99999"? "100000" "100001" "100002" "100003" "100004" "100005"
#[17] "100006" "100007" "100008" "100009" "100010"


id2 <- format(1:110000, scientific = FALSE,trim=TRUE) 
id2[99990:100010]
# [1] "99990"? "99991"? "99992"? "99993"? "99994"? "99995"? "99996"? "99997" 
?#[9] "99998"? "99999"? "100000" "100001" "100002" "100003" "100004" "100005"
#[17] "100006" "100007" "100008" "100009" "100010"
A.K.


----- Original Message -----
From: Mathieu Basille <basille.web at ase-research.org>
To: David Winsemius <dwinsemius at comcast.net>
Cc: r-help at r-project.org
Sent: Tuesday, July 30, 2013 2:07 PM
Subject: Re: [R] 'format' behaviour in a 'apply' call depending on 'options(digits = K)'

Thanks David for your interest. I have to admit that your answer puzzles me 
even more than before. It seems that the underlying problem is way beyond 
my R skills...

The generation of id2 is indeed quite demanding, especially compared to a 
simple 'as.character' call. Anyway, since it seems to be system specific, 
here is the sessionInfo() that I forgot to attach to my first message:

R version 3.0.1 (2013-05-16)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
? [1] LC_CTYPE=fr_FR.UTF-8? ? ?  LC_NUMERIC=C
? [3] LC_TIME=fr_FR.UTF-8? ? ? ? LC_COLLATE=fr_FR.UTF-8
? [5] LC_MONETARY=fr_FR.UTF-8? ? LC_MESSAGES=fr_FR.UTF-8
? [7] LC_PAPER=C? ? ? ? ? ? ? ?  LC_NAME=C
? [9] LC_ADDRESS=C? ? ? ? ? ? ?  LC_TELEPHONE=C
[11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats? ?  graphics? grDevices utils? ?  datasets? methods?  base

In brief: last stable R available under Debian Testing... Hopefully this 
can help tracking down the problem.
Mathieu.


Le 07/30/2013 01:58 PM, David Winsemius a ?crit :
______________________________________________
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.