开发者

strptime( ) function in [R] to manipulate date/time class

So i'm working with a simple data set wanting to plot day x frequency

the date is given in a human-readable format of

> head(gb.day)
[1] Sep 12, 2011 11:59 PM Sep 12, 2011 11:59 PM Sep 12, 2011 11:58 PM
[4] Sep 12, 2开发者_C百科011 11:56 PM Sep 12, 2011 11:55 PM Sep 12, 2011 11:55 PM
644 Levels: Sep 12, 2011 01:09 PM Sep 12, 2011 01:10 PM ... Sep 12, 2011 11:59 PM

and is read as a factor.

I'm trying to convert it into a date via the strptime( ) function in [R] and am running into problems

> strptime(gb.day,"%b %d %Y %l %p")

I thought would be the correct parameters but is returning NAs Are my parameters correct?

Are there any other suggestions to accomplish this simple hassle


You can also add the comma in the strptime() format:

R> var <- "Sep 12, 2011 11:59 PM"
R> strptime(var, "%b %d, %Y %I:%M %p")
[1] "2011-09-12 23:59:00"
R> 

Apart from that, your problem may have the use of factor encoding. Also try

R> strptime( as.character(gb.day) ,"%b %d, %Y %I:%M %p")

Lastly, you may have inadvertently swapped a '1' (digit one) or an 'I' (uppercase i).


from datetime import datetime

start_time = datetime.strptime(datetime.now(), "%Y-%m-%d %H:%M:%S")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜