ryszard.czerminski@pharma.novartis.com
2003-Oct-31 15:47 UTC
[R] print(), cat() and simple I/O in R
I am trying to produce rather mundane output of the form e.g. pi, e = 3.14 2.718 The closest result I achieved so far with print() is:> print (c(pi, exp(1)), digits = 3)[1] 3.14 2.72> print(c("pi, e =", pi, exp(1)), digits = 3)[1] "pi, e =" "3.14159265358979" "2.71828182845905" I understand that c() promotes floats to strings and this is why I get what I get. and with cat() (it apparently does not have equivalent of digits" parameter)> cat ("pi, e =", pi, exp(1), "\n")pi, e = 3.141593 2.718282 Any pointers with respect how can I print what I want to print would be greatly appreciated. Ryszard [[alternative HTML version deleted]]
Have you considered "round" and "paste"? hope this helps. spencer graves ryszard.czerminski at pharma.novartis.com wrote:>I am trying to produce rather mundane output of the form e.g. > >pi, e = 3.14 2.718 > >The closest result I achieved so far with print() is: > > > >>print (c(pi, exp(1)), digits = 3) >> >> >[1] 3.14 2.72 > > > >>print(c("pi, e =", pi, exp(1)), digits = 3) >> >> >[1] "pi, e =" "3.14159265358979" "2.71828182845905" >I understand that c() promotes floats to strings and this is why I get >what I get. > >and with cat() (it apparently does not have equivalent of digits" >parameter) > > >>cat ("pi, e =", pi, exp(1), "\n") >> >> >pi, e = 3.141593 2.718282 > >Any pointers with respect how can I print what I want to print would be >greatly appreciated. > > >Ryszard > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >
See format(), formatC() and sprintf(). /Henrik> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > ryszard.czerminski at pharma.novartis.com > Sent: den 31 oktober 2003 16:48 > To: r-help at stat.math.ethz.ch > Subject: [R] print(), cat() and simple I/O in R > > > I am trying to produce rather mundane output of the form e.g. > > pi, e = 3.14 2.718 > > The closest result I achieved so far with print() is: > > > print (c(pi, exp(1)), digits = 3) > [1] 3.14 2.72 > > > print(c("pi, e =", pi, exp(1)), digits = 3) > [1] "pi, e =" "3.14159265358979" "2.71828182845905" > I understand that c() promotes floats to strings and this is > why I get > what I get. > > and with cat() (it apparently does not have equivalent of digits" > parameter) > > cat ("pi, e =", pi, exp(1), "\n") > pi, e = 3.141593 2.718282 > > Any pointers with respect how can I print what I want to > print would be > greatly appreciated. > > > Ryszard > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailma> n/listinfo/r-help > >
?format ?formatC> Date: Fri, 31 Oct 2003 10:47:36 -0500 > From: ryszard.czerminski at pharma.novartis.com > Sender: r-help-bounces at stat.math.ethz.ch > Precedence: list > > I am trying to produce rather mundane output of the form e.g. > > pi, e = 3.14 2.718 > > The closest result I achieved so far with print() is: > > > print (c(pi, exp(1)), digits = 3) > [1] 3.14 2.72 > > > print(c("pi, e =", pi, exp(1)), digits = 3) > [1] "pi, e =" "3.14159265358979" "2.71828182845905" > I understand that c() promotes floats to strings and this is why I get > what I get. > > and with cat() (it apparently does not have equivalent of digits" > parameter) > > cat ("pi, e =", pi, exp(1), "\n") > pi, e = 3.141593 2.718282 > > Any pointers with respect how can I print what I want to print would be > greatly appreciated. > > > Ryszard > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > >-- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________]