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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, Sep 24, 2002 at 11:34:05PM +1200, Ko-Kang Kevin Wang wrote:> 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"))[...]> 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"You want cat() instead of print(), and sprintf() is one way to get finer control over how things are printed:> answer <- c(2,1,0,4,5) > print(answer); cat(sprintf("The best fit is with %.0f-degree polynomial\n",which.min(answer)-1)) [1] 2 1 0 4 5 The best fit is with 2-degree polynomial Dirk -- Good judgement comes from experience; experience comes from bad judgement. -- Fred Brooks -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 24 Sep 2002, Dirk Eddelbuettel wrote: |On Tue, Sep 24, 2002 at 11:34:05PM +1200, Ko-Kang Kevin Wang wrote: ... |You want cat() instead of print(), and sprintf() is one way to get finer |control over how things are printed: | |> answer <- c(2,1,0,4,5) |> print(answer); cat(sprintf("The best fit is with %.0f-degree polynomial\n", | which.min(answer)-1)) |[1] 2 1 0 4 5 |The best fit is with 2-degree polynomial Or just use cat(..., sep="") cat("The best...", which.min(abwer)-1, sep="") Ott -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello, For the second question, use the option "sep" within the paste command. paste("The best fit is with ", which.min(answer) - 1,"-degree polynomial", sep="") Regards, Carlos. -----Mensaje original----- De: owner-r-help at stat.math.ethz.ch [mailto:owner-r-help at stat.math.ethz.ch]En nombre de Ko-Kang Kevin Wang Enviado el: martes, 24 de septiembre de 2002 13:34 Para: R Help Asunto: [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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ _____ The information in this email is confidential and it may not be disclosed or used by anyone other than the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted is prohibited and may be unlawful. Minorplanet cannot accept responsibility for the accuracy or completeness of this email as it has been transmitted over a public network. If you suspect that the email may have been amended, please call the sender. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._