[R] vector sprintf argument [SEC=UNCLASSIFIED]

Crombie, Joe Joe.Crombie at brs.gov.au
Fri Nov 30 03:33:50 CET 2007


Hi Tom,

Try this:

> G <- "Number: %s"
> sprintf(G, toString(A))
[1] "Number: 3, 4, 5"

Cheers  Joe

 
Joe Crombie
 
Biosecurity and Information Sciences
Bureau of Rural Science
Canberra  Australia
 
p: +61 2 6272 5906
e: joe.crombie at brs.gov.au
 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Tom Sgouros
Sent: Friday, 30 November 2007 12:43 PM
To: r-help at r-project.org
Subject: [R] vector sprintf argument


Hello all:

If I have a vector and a format, I want to do this:

 > A <- c(3,4,5)
 > F <- "Number: %d, %d, %d"
 > sprintf(F,A)

This doesn't work because A isn't three arguments, it's just one.  Is
there a way to peel the vector members out of A so that sprintf can get
at them?

I would like to do this because I have a large set of variable-length
data that I'd like to print out in fancy formatted form.  The vectors
range in length from 2 to 7.  Each row is different, so I had been
hoping to do this with an array of formats, too.

I feel like I'm either overlooking something obvious, or have determined
to do this in an un-R fashion.  Any advice is welcome.  (On this topic,
that is.)

Many thanks,

 -tom


--
 ------------------------
 tomfool at as220 dot org
 http://sgouros.com
 http://whatcheer.net

______________________________________________
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.

------IMPORTANT - This message has been issued by The Department of Agriculture, Fisheries and Forestry (DAFF). The information transmitted is for the use of the intended recipient only and may contain confidential and/or legally privileged material. It is your responsibility to check any attachments for viruses and defects before opening or sending them on. 

Any reproduction, publication, communication, re-transmission, disclosure, dissemination or other use of the information contained in this e-mail by persons or entities other than the intended recipient is prohibited. The taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error please notify the sender and delete all copies of this transmission together with any attachments. If you have received this e-mail as part of a valid mailing list and no longer want to receive a message such as this one advise the sender by return e-mail accordingly. Only e-mail correspondence which includes this footer, has been authorised by DAFF 
------



More information about the R-help mailing list