[R] Date formate “ %y-%d-%m “ or “ %m-%d-%y “ ?

Rui Barradas rui1174 at sapo.pt
Wed Apr 11 18:21:44 CEST 2012


Hello,

>
> I would like to know for each variable what is date format?
> Is it  “ %y-%d-%m “  or  “ %m-%d-%y “   
> 
It's 4 digits, with uppercase 'Y'

Try

Data <- data.frame(var1=c("12-15-2011", "12-15-2011", "12-17-2001"),
			var2=c("2001-15-12", "2001-15-01", "2001-15-01"),
			stringsAsFactors=FALSE )
str(Data)

yr <- sapply(sapply(Data, strsplit, "-"), function(x) which(nchar(x) == 4))
yr
[1] 3 3 3 1 1 1

To have the result with the same dimensions as your original data.frame
(but with a different class, I don't believe it matters)

matrix(yr, ncol=ncol(Data))

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Date-formate-y-d-m-or-m-d-y-tp4548736p4549342.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list