문제

I am trying to produce a barplot that shows each of the four surgeons on the x-axis and the sum of each one's surgery durations on the y-axis, help is much appreciated. "Surgeon" is character type and "Duration" is 'times' type from the chron package.

Sample Data:

Surgeon Duration
Jack    00:22:00
Ben     00:34:00
Charles 03:12:00
Hank    01:15:00
Jack    00:59:00
Ben     00:44:00
Hank    01:46:00
Hank    00:32:00
Ben     00:49:00
Ben     06:19:00
Charles 07:02:00
Jack    00:58:00
Jack    00:21:00
도움이 되었습니까?

해결책

Assuming that you have an input file called Input.txt which contains the data in your question, this will get you pretty close. For your reference, you should look at the documentation to learn how to get stuff out of the chron object.

# Aggregation
library(chron)
data = read.table("Input.txt", header=T, as.is =c(T,T))
data$Duration = chron(times=data$Duration)
processed = aggregate(Duration ~ Surgeon, data, sum)
print(processed)

# This will do total seconds, but you can change it to whatever you want to plot.
total_seconds = hours(processed$Duration) * 3600 +  minutes(processed$Duration) * 60 + seconds(processed$Duration)
barplot(total_seconds, names.arg=processed$Surgeon)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top