Reputation: 29
I have a data frame containing time as a character type in the following manner.
time=c("5 mins 30 seconds","1 min 46 seconds","6 mins 40 seconds","20 seconds","2 seconds")
student=c("A","B","C")
df<-data.frame(student,time)
I want to sort time taken by them and then plot. How should I proceed?
Also how to convert time to INT type in seconds?
Upvotes: 0
Views: 94
Reputation: 607
If the format remains same then, we can use strptime function in R
time<- c("5 mins 30 seconds","3 mins 46 seconds","6 mins 40 seconds")
times <- strptime(time, "%M mins %S seconds")
times <- format(times, "%H:%M:%S")
student=c("A","B","C")
df<-data.frame(student,times)
Upvotes: 1