Skip to content
Advertisement

How can I create a column with time HH:MM from a timestamp column with time HH:MM:SS in my dataset [closed]

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)
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement