How can I create a column with time HH:MM from a timestamp column with time HH:MM:SS in my dataset
Advertisement
Answer
We can use
library(data.table) df1$col2 <- format(as.POSIXct(as.ITime(df1$col)), "%H:%M")
Or in base R
with sub
df1$col2 <- sub("\d+$", "", df1$col)