[R] sprintf question

Paul Roebuck roebuck at mdanderson.org
Wed May 3 18:31:53 CEST 2006


How would one go about getting sprintf to use the
values of a vector without having to specify each
argument individually?

> v <- c(1, 2, -1.197114, 0.1596687)
> iv <- c(3, 1, 2, 4)
> sprintf("%9.2f\t%d\t%d\t%8.3f", v[3], v[1], v[2], v[4])
[1] "    -1.20\t1\t2\t   0.160"

Essentially, desired effect would be something like:
> sprintf("%9.2f\t%d\t%d\t%8.3f", v[iv]) # wish it worked

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)




More information about the R-help mailing list