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
Here's one way to get rid of leading zeros before the decimal point:> gsub("^0\\.", "\\.", as.character(lambda))[1] "0" ".005" ".01" ".02" ".04" ".08" Sarah On Tue, Nov 29, 2011 at 12:04 PM, Michael Friendly <friendly at yorku.ca> wrote:> 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") > > ---- Sarah Goslee http://www.functionaldiversity.org
Omitting the leading zero is dangerous, since the decimal point can disappear in
a poor hardcopy leading to later misinterpretation.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Michael Friendly <friendly at yorku.ca> wrote:
>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
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
Possibly Parallel Threads
- finding interpolated values along an empirical parametric curve
- ridge regression - covariance matrices of ridge coefficients
- NAMESPACES for data only packages
- replace double backslash with singel backslash
- R: Tools for thinking about data analysis and graphics