How to make an empty vector of POSIXct

后端 未结 6 1309
孤街浪徒
孤街浪徒 2021-02-12 03:21

I want to make an empty vector of POSIXct so that I can put a POSIXct in it:

vec <- vector(\"POSIXct\", 10)
vec
vec[1] <- \"2014-         


        
6条回答
  •  醉梦人生
    2021-02-12 04:22

    I usually initialize things to NA:

    as.POSIXct(rep(NA, 10))
    

    works well in this case. It's explicitly doing what happens under-the-hood in @RichardScriven's answer---see the comments there for a longer discussion.

提交回复
热议问题