Try converting it from factor to character first:
as.numeric(as.date(paste(date1)))
By the way, if you don't need the date package for a particular reason
you could use the built in Date class which does have an as.Date.factor
method.
On 9/22/05, sloan jones <sledepi at operamail.com>
wrote:> I Have been trying to convert a vector of dates into julian dates using the
following commands: as.date & as.numeric. I can convert a date no problem
by doing the following:
>
> as.numeric (as.date ("9/21/2004"))
>
> but as soon as I try to do an entire vector I am given the following:
>
> as.numeric (as.date(date1))
> Error in as.date(date1) : Cannot coerce to date format
>
> I have tried starting with a number of different date formats including
dd/mm/yy, dd/mm/yyyy, month, day, year..
>
> Following is a sample of the vector of dates that I am using:
>
> > date1
> [1] 7/1/2005 4/27/2005 7/15/2004 11/30/2004 1/8/2005 2/7/2005
> [7] 7/17/2004 4/1/2004 1/4/2005 12/27/2004 1/5/2005 5/17/2005 ....
>
> it is a factor and its mode is numeric.
>
> What do I need to do?
>
> Sloan
>
> --
> _______________________________________________
> Surf the Web in a faster, safer and easier way:
> Download Opera 8 at http://www.opera.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>