user1471980
user1471980

Reputation: 10626

how format factor Hour and Minute as time in R

is there a way to format below data points as Time in R without any date associated with them. For example,

df

Time 00:00 00:15 00:30 00:45

if I do,

    Df$Time<-as.POSIXct(df$Time, format="%H:%M")

it turns into as below:

2013-04-26 00:00:00 EDT
2013-04-26 00:15:15 EDT

Upvotes: 1

Views: 3397

Answers (1)

Tyler Rinker
Tyler Rinker

Reputation: 109874

There's likely a better way but...

x <-factor(c('00:00', '00:15', '00:30', '00:45'))

library(chron)
times(paste0("00:", as.character(x)))

Upvotes: 1

Related Questions