[R] print(), paste()
Bartz, Kevin
Kevin.Bartz at FMR.COM
Tue Sep 24 15:36:19 CEST 2002
1) Use "cat" instead of "print".
2) Use paste's "sep" argument. I find it particularly convenient to define:
"%&%" <- function(a, b) paste(a, b, sep="")
You can then write: cat("The best fit is with " %&% (which.min(answer) - 1)
%&% "-degree polynomial")
Good luck.
Kevin
-----Original Message-----
From: Ko-Kang Kevin Wang [mailto:kwan022 at stat.auckland.ac.nz]
Sent: Tuesday, September 24, 2002 7:34 AM
To: R Help
Subject: [R] print(), paste()
Hi,
Suppose I have the following lines at the end of a function:
answer <- c(2, 1, 0, 4, 5) # In fact, answer will be generate in my
# function
print(answer) # Print the answer
# Now, find the best fitted n degree polynomial
print(paste("The best fit is with", which.min(answer) - 1,
"-degree polynomial"))
this will return:
[1] 2 1 0 4 5
[1] "The best fit is with 2 -degree polynomial"
Two questions:
1) How can I supress the [1] in the second line in the output?
2) The second line has ...with 2 -degree... , how can I make it display
...with 2-degree...?
In other words I'd like my output to look like:
[1] 2 1 0 4 5
"The best fit is with 2-degree polynomial"
Cheers,
Kevin
----------------------------------------------------------------------------
--
Ko-Kang Kevin Wang
Postgraduate PGDipSci Student
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list