Several Basic Questions
On Tue, 20 May 2003, Minghua Yao wrote:
I am having several basic questions that I haven't found the answer to from the manuals: 1. How to remove "[1]" when a single line message is printed?
Use cat()
2. How to print several variables (e.g., a character string and a numeric variable) at the same line?
Use cat()
3. How to have the control of the accuracy of variables? e.g., in the following,
x<-1134567.1 y<-0.19 z<-x-y z
[1] 1134567
I want variable to have an accuracy of 2 digits behind the decimal point instead of all the digits behind the point being cut off.
Use cat, round and format:
cat(format(round(z, 2)), "\n")
1134566.91 These may not be explicit in the R manuals, but they are in all good books on R (see the FAQ).
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595