Converting numeric to date issues

前端 未结 1 1351
不知归路
不知归路 2021-01-29 06:08

I have a date column that is numeric as follows

       Date1
       4010
       5178
       5494
       6750
       7106
       39
       39
       172
       17         


        
相关标签:
1条回答
  • 2021-01-29 06:43
    # First I copied the data from your question
    df <- read.table(con <-file("clipboard"), header = T)
    df
    
    # Convert the format
    df1 <- as.Date(df$Date1, origin = "1994-11-08")
    df1
    > as.data.frame(gsub("-", ".", df1))
       gsub("-", ".", df1)
    1           2005.10.31
    2           2009.01.11
    3           2009.11.23
    4           2013.05.02
    5           2014.04.23
    6           1994.12.17
    7           1994.12.17
    8           1995.04.29
    9           1999.07.09
    10          2006.03.22
    

    Note, however, that there seems to be an error in the data (or at least the results you are expecting to get from the data -- how did you produce these numbers?):

    • The input for row 6 is 39
    • The input for row 7 is 39 and
    • The input for row 8 is 172

    172 - 39 = 133

    However you expect the dates for row 6 and 7 to be 1994.02.22 and the result for row 8 to be 1994.08.03. This is not mathematically possible, as there are 162 days between those 2 dates.

    0 讨论(0)
提交回复
热议问题