why all date strings are changed into numbers?

前端 未结 2 591
闹比i
闹比i 2021-01-20 01:35
start=as.Date(\"2013-09-02\")
x[1:140]<-start
for(i in 2:140){
  x[i]<-x[i-1]+1 }

what i get is something as such:

[1] \"2013         


        
2条回答
  •  独厮守ぢ
    2021-01-20 02:29

    That's just a weird behaviour of matrix. Dates are internally stored as an integer of the number of days since 1st Jan 1970. Those are the numbers that you are seeing.

    Probably the best option is to store them in a data frame instead.

    FYI, you can create a sequence of dates using seq.

    x <- seq(as.Date("2013-09-02"), length.out = 140, by = "1 day")
    

提交回复
热议问题