Any ideas what is the problem with this code?> N <- 2; c(Sys.Date(), sprintf('N = %d', N))[1] "2012-01-10" NA Warning message: In as.POSIXlt.Date(x) : NAs introduced by coercion Best regards, Ryszard Ryszard Czerminski AstraZeneca Pharmaceuticals LP 35 Gatehouse Drive Waltham, MA 02451 USA 781-839-4304 ryszard.czerminski@astrazeneca.com -------------------------------------------------------------------------- Confidentiality Notice: This message is private and may ...{{dropped:11}}
On 12-01-10 8:04 AM, Czerminski, Ryszard wrote:> Any ideas what is the problem with this code? > >> N<- 2; c(Sys.Date(), sprintf('N = %d', N)) > [1] "2012-01-10" NA > Warning message: > In as.POSIXlt.Date(x) : NAs introduced by coercionYou are trying to create a vector combining a Date object and a character object. R is trying to coerce both objects to dates, and that fails. You probably want two strings; so convert the date explicitly: c(as.character(Sys.Date()), sprintf('N = %d', N)) (or use format or some other function to convert the date to a string.) Duncan Murdoch> > Best regards, > Ryszard > > Ryszard Czerminski > AstraZeneca Pharmaceuticals LP > 35 Gatehouse Drive > Waltham, MA 02451 > USA > 781-839-4304 > ryszard.czerminski at astrazeneca.com > > > -------------------------------------------------------------------------- > Confidentiality Notice: This message is private and may ...{{dropped:11}} > > ______________________________________________ > 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.
My best guess is that you are misunderstanding what the c() function does. I'd suggest reading the help page for c, obtained by typing ?c Note that if you supply c() with objects of different types (as you have), the results will probably not be what you wanted. Given what c() does, your output and warning message make sense. But I'm unable to figure out what you're really trying to do. Something like this, perhaps?> N <- 2; sprintf('N = %d', N)[1] "N = 2" -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/10/12 5:04 AM, "Czerminski, Ryszard" <Ryszard.Czerminski at astrazeneca.com> wrote:>Any ideas what is the problem with this code? > >> N <- 2; c(Sys.Date(), sprintf('N = %d', N)) >[1] "2012-01-10" NA >Warning message: >In as.POSIXlt.Date(x) : NAs introduced by coercion > >Best regards, >Ryszard > >Ryszard Czerminski >AstraZeneca Pharmaceuticals LP >35 Gatehouse Drive >Waltham, MA 02451 >USA >781-839-4304 >ryszard.czerminski at astrazeneca.com > > >-------------------------------------------------------------------------- >Confidentiality Notice: This message is private and may ...{{dropped:11}} > >______________________________________________ >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.