Re: [R] using sprintf with dates

2007-10-02 Thread Alberto Monteiro
stephen bond wrote:
> 
> foot=function(){
>   str1=format(Sys.Date,"%Y%m%d")
>   sprintf("99%-4s%s","nm",str1)
> }
> 
> I wanted to have "99nm  20071002" as the output.
> 
Sys.Date is a function. It's perfectly possible
to write string <- format(Sys.Date, "%s") (or, generically,
string <- format(sin, "%s"), etc), but it will just put some
description of the function in the string.

Also, the assignment in R is "<-", not "=".

Try:

foot <- function(){
  str1 <- format(Sys.Date(),"%Y%m%d")
  sprintf("99%-4s%s","nm",str1)
}

Alberto Monteiro

__
R-help@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.


Re: [R] using sprintf with dates

2007-10-02 Thread Jeffrey Horner
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

__
R-help@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.


[R] using sprintf with dates

2007-10-02 Thread stephen bond
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.

__
R-help@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.