Re: [R] Simple Date problems with cbind

From: Tony Plate <tplate_at_acm.org>
Date: Tue 30 Jan 2007 - 20:42:54 GMT

> It is probably something blindingly simple but can > anyone suggest something?

You need to use the format code "%Y" for 4-digits years. You need to create a data frame using 'data.frame()' (cbind() creates a matrix when given just vectors).

> as.Date(c("2005/01/24" ,"2006/01/23" ,"2006/01/23"), "%Y/%m/%d")
[1] "2005-01-24" "2006-01-23" "2006-01-23"

> data.frame(int=1:3, date=as.Date(c("2005/01/24" ,"2006/01/23"
,"2006/01/23"), "%Y/%m/%d"))

   int date

1   1 2005-01-24
2   2 2006-01-23
3   3 2006-01-23

> (x <- data.frame(int=1:3, date=as.Date(c("2005/01/24" ,"2006/01/23"
,"2006/01/23"), "%Y/%m/%d")))

   int date

1   1 2005-01-24
2   2 2006-01-23
3   3 2006-01-23

> class(x)

[1] "data.frame"
> sapply(x, class)

       int date
"integer" "Date"
>


R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Wed Jan 31 07:49:05 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 30 Jan 2007 - 21:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.