[R] using sprintf with dates
Jeffrey Horner
jeff.horner at vanderbilt.edu
Tue Oct 2 15:49:21 CEST 2007
stephen bond wrote on 10/02/2007 08:36 AM:
> hello,
>
> Please help with using sprintf with character variables:
> The following does not produce what i intended
>
> foot=function(){
> str1=format(Sys.Date,"%Y%m%d")
> sprintf("99%-4s%s","nm",str1)
> }
>
> I wanted to have "99nm 20071002" as the output.
You forgot the parens after Sys.Date:
foot=function(){
str1=format(Sys.Date(),"%Y%m%d")
sprintf("99%-4s%s","nm",str1)
}
Jeff
--
http://biostat.mc.vanderbilt.edu/JeffreyHorner
More information about the R-help
mailing list