[R] vector sprintf argument

Tom Sgouros tomfool at as220.org
Fri Nov 30 02:42:34 CET 2007


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



More information about the R-help mailing list