transfer date data from SAS into R

前端 未结 1 1142
野性不改
野性不改 2021-01-14 09:27

It\'s quite weird to ask this question that I apply a sas7 dataset into R. One of my variable is visit_date

now it looks like this, i am wondering where i can transf

1条回答
  •  北海茫月
    2021-01-14 10:15

    Those "dates" are clearly using a different origin/offset than the typical POSIX standard that would work with this conversion. R generally uses YYYY-MM-DD format

    as.Date(ffffd, origin="1970-01-01")
    
    > head( as.Date(ffffd, origin="1970-01-01") )
    [1] "2016-10-03" "2016-10-17" "2016-10-31" "2016-11-14" "2016-11-28" "2016-09-25"
    

    So you need to establish the correct origin. If it was 1960-01-01, then none of those dates is greater than 08-01-2010.

    > sum( as.Date(ffffd, origin="1960-01-01") >= as.Date("2010-08-01") )
    [1] 0
    > sum( as.Date(ffffd, origin="1960-01-01") < as.Date("2010-08-01") )
    [1] 336
    

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