Jed
Jed

Reputation: 399

Changing a time columne, from a character variable to a time variable in r?

I created a data frame, DF.

time <- c("10:00", "11:00", "12:00", "13:00")

temperature <- c("15", "16", "17", "18")

DF <- data.frame(time, temperature)

R views the “time” column as a list of characters. How do I get it too recognize the “time” column as a list of times?

I usually use the following code;

DF$time <- as.hms(DF$time).

However in this case the time column does not include seconds, so that piece of code does not work.

Upvotes: 0

Views: 35

Answers (1)

user2974951
user2974951

Reputation: 10375

paste0(time,":00") to add your precious seconds.

Upvotes: 1

Related Questions