[R] controlling printing precision in paste()
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Fri Sep 17 16:00:24 CEST 2004
Hi RenE,
you could easily modify the "paste" function to get what you want,
i.e.,
paste. <- function (..., digits=16, sep=" ", collapse=NULL) {
args <- list(...)
if (length(args) == 0)
if (length(collapse) == 0)
character(0)
else ""
else{
for(i in seq(along=args))
if(is.numeric(args[[i]])) args[[i]] <-
as.character(round(args[[i]], digits)) else args[[i]] <-
as.character(args[[i]])
.Internal(paste(args, sep, collapse))
}
}
############
x <- rnorm(3)
x
paste.("x1=", x[1], ", x2=", x[2], ", x3=", x[3], sep="",
collapse=",")
paste.("x1=", x[1], ", x2=", x[2], ", x3=", x[3], digits=3, sep="",
collapse=",")
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "RenE J.V. Bertin" <rjvbertin at hotmail.com>
To: <r-help at r-project.org>
Sent: Friday, September 17, 2004 3:21 PM
Subject: [R] controlling printing precision in paste()
> Hello,
>
> I can't seem to find the way to modify the precision with which
> paste() prints its floating point numbers, more precisely the number
> of decimal digits printed. This is apparently not controlled by
> options( digits= ), and there is no appropriate argument to paste()
> itself.
>
> Is this possible, and if so, how? Does one have to use round() for
> all individual arguments, or is there a more global approach?
>
> Thanks,
> RenE Bertin
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list