Hello, everyone, 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? 2. How to print several variables (e.g., a character string and a numeric variable) at the same line? 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. Thank you in advance for any help. Minghua
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
I get the digest, so apologies if this has already been sorted out. Perhaps there is some platform dependence to this? Following Ripley's suggestion, I still get what Mingua got:> x <- 1134567.1 > y <- 0.19 > z <- x - y > version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor 7.0 year 2003 month 04 day 16 language R> win.version()[1] "Windows 2000 Professional (build 2195) Service Pack 2.0"> cat(format(round(z, 2)), "\n")1134567 ********************************************************************** This message is intended only for the designated recipient(s). ... {{dropped}}