Change from date and hour format to numeric format

后端 未结 2 1149
情深已故
情深已故 2020-12-17 16:46

I am working in R and I need to change from a column in format

9/27/2011  3:33:00 PM 

to a value format. In Excel I can use the function <

2条回答
  •  醉梦人生
    2020-12-17 16:47

    This was useful for me:

    > test=as.POSIXlt("09/13/2006", format="%m/%d/%Y")
    > test
    [1] "2006-09-13"
    > 1900+test$year
    [1] 2006
    > test$yday
    [1] 255
    > test$yday/365
    [1] 0.6986301
    > 1900+test$year+test$yday/366
    [1] 2006.697
    

    You can use similar approaches if you need day numbers like in Excel.

提交回复
热议问题