How to initialize data.frame with column of type POSIXct?

前端 未结 2 1982
余生分开走
余生分开走 2021-01-08 00:43

I can initialize a data.frame via

df <- data.frame(a=numeric(), b=character())

But how do I define a column of type POSIXct?

<         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-08 01:31

    You can try

    df <- data.frame(a=numeric(), b=character(), c=as.POSIXct(character()))
    

    Similarly, you can create a POSIXct column of NAs in a data frame with > 0 rows by creating a new column with as.POSIXct(NA).

提交回复
热议问题