I'm having a data table, which can look like this:
year <- c("2018", "2018", "2018", "2018")
month <- c("01","01","01","01")
day <- c("01", "02","03","04")
hour <- c("00","01","02","03")
id <- c(8750, 3048, 3593, 8475)
type <- c("ist","plan","ist","plan")
dt.test <- data.table(year, month, day, hour, id, type)
Now I want to combine the columns year
, month
, day
and hour
to a single column called date
of the form "2018-01-01 00"
, "2018-01-02 01"
and so on. In the end I need a data table with the columns date
(combined one), id
and type
. I know how to do this with paste()
, but is there another fast and efficient way to do so?