Create an r data.table with a date formatted column -


i'm trying create data.table date/time formatted column populated in next steps. i've tried bunch of different functions can't find 1 package wants.

see column3 in below examples:

require(data.table) num_rows <- 5 dt <- data.table(column1 = character(num_rows),                  column2 = integer(num_rows),                  column3 = date(num_rows)                  )  dt <- data.table(column1 = character(num_rows),                  column2 = integer(num_rows),                  column3 = posixct(num_rows)                  )  dt <- data.table(column1 = character(num_rows),                  column2 = integer(num_rows),                  column3 = idatetime(num_rows)                  ) 

what function creates date or time column in data.table? can't find anywhere.

cheers.

note integer(num_rows) makes vector of 0s, character(num_rows) makes vector of ""s etc.

so initialise dates value, e.g.

column3=rep(sys.time(), num_rows) # posixct 

or

column3=rep(sys.date(), 3) # date 

i'd recommend initialising default date/datetime makes sense application (e.g. column2 initialised 0 , column1 initialised ""). maybe default origin value e.g. 1970-01-01 00:00 (column3=rep(as.posixct('1970-01-01 00:00'), num_rows))


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -