Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Building Strings

A typical usage of paste is to build a label vector to be used in a plot. The labels may want to include both the variable values being plotted and perhaps the percentage of observations having that value.



> labels <- c("A", "B", "C", "D")
> per    <- c(25, 10, 15, 45)
> paste(labels, rep(" (", 4), per, rep("%)",4), sep="")
[1] "A (25%)" "B (10%)" "C (15%)" "D (45%)"
> sprintf("%s (%d%%)", labels, per)
[1] "A (25%)" "B (10%)" "C (15%)" "D (45%)"



Copyright © 2004-2010 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010