[R] Simple Date problems with cbind
John Kane
jrkrideau at yahoo.ca
Tue Jan 30 21:27:24 CET 2007
I am clearly misunderstanding something about dates
and my reading of the help and RSiteSearch have not
turned up anything.
I have a variable of class "Date" and I want to add
include it in a data.frame. However when do a cbind
the date var is coerced into a numeric.
However when I tried to create a example I also seem
to be doing something wrong as I cannot seem even to
create a date class var even when I try to copy an
example from the Help
Example from Help
dates <- c("02/27/92", "02/27/92", "01/14/92",
"02/28/92", "02/01/92")
max <-as.Date(dates, "%m/%d/%y")
max
class(max)
Results
> dates <- c("02/27/92", "02/27/92", "01/14/92",
"02/28/92", "02/01/92")
> max <-as.Date(dates, "%m/%d/%y")
> max
[1] "1992-02-27" "1992-02-27" "1992-01-14"
"1992-02-28" "1992-02-01"
> class(max)
[1] "Date"
My example
cc <- c("2005/01/24" ,"2006/01/23" ,"2006/01/23",
"2006/01/23")
xx <- as.Date(cc, "%y/%m/%d")
xx
class(xx)
Results
> cc <- c("2005/01/24" ,"2006/01/23" ,"2006/01/23",
"2006/01/23")
> xx <- as.Date(cc, "%y/%m/%d")
> xx
[1] NA NA NA NA
> class(xx)
[1] "Date"
And on to the cbind problem
jj <- 1:5
cbind(jj,max)
jj max
[1,] 1 8092
[2,] 2 8092
[3,] 3 8048
[4,] 4 8093
[5,] 5 8066
I have tried various as.Date etc approcaes
It is probably something blindingly simple but can
anyone suggest something?
Thanks
More information about the R-help
mailing list