[R] format numbers without leading or trailing 0s

Michael Friendly friendly at yorku.ca
Tue Nov 29 18:04:41 CET 2011


A simple question, but I can't find something to do what I want:

Given: a vector of numbers, like

lambda <- c(0, 0.005, 0.01, 0.02, 0.04, 0.08)

Desired: format them in minimal space for use as plot labels, ie, 
without leading or tailing 0s. For this example:

lambdaf <- c("0", .005", ".01", ".02", ".04", ".08")

-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list