r - Transform "ambigous" factor to Posixct value -


this extract dates.

df<-structure(c(2l, 3l, 1l, 4l, 5l), .label = c("05jul2014:00:00:00",  "07feb2014:00:00:00", "10jul2012:00:00:00", "19apr1998:00:00:00",  "22dec2010:00:00:00"), class = "factor") 

i transform date or posixct.

i tried :

as.posixct(df,"%d%b%y:%h:%m:%s") 

but dont seems solution. can show me mistake ?

edit : tried this:

as.posixct(df, format = "%d%b%y:%h:%m:%s") 

but obtain

na na na na 

re edit :

as.posixct("07feb2014:00:00:00", format = "%d%b%y:%h:%m:%s") 

return

na 

but

as.posixct("072014:00:00:00", format = "%d%y:%h:%m:%s") 

return

"2014-09-07 cest" 

%b dont seems understand "feb" , computer use "french" locale... (but dont seems understand fev or jan (instead of feb , jan)

final? edit

i found solution using function :

 sys.setlocale("lc_time", "c") 

i dont realy understand why, it's seems ok.

thks

you setting locale environment generic "c" defaulting english months:

need convert charter before using strptime or as.posixct:

dfc <- as.character(df) as.posixct(dfc, format="%d%b%y:%h:%m:%s") [1] "2014-02-07 pst" "2012-07-10 pdt" "2014-07-05 pdt" "1998-04-19 pdt" [5] "2010-12-22 pst"  > sys.getlocale() [1] "en_us.utf-8/en_us.utf-8/en_us.utf-8/c/en_us.utf-8/en_us.utf-8" 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -