我Dataframe
稱爲copy1
:計算平均時間中的R
copy1
Source: local data frame [4 x 4]
Groups: GM [2]
GM Avg.Start.Time Avg.Close.Time Avg.Last.Task.Duration
(fctr) (fctr) (fctr) (int)
1 ED 13:15 16:16 181
2 ED 16:12 17:44 92
3 LD 15:32 17:27 115
4 LD 14:38 17:11 153
我想計算Avg.Close.Time
每GM
我曾嘗試:
copy1$Avg.Start.Time <-strptime(copy1$Avg.Start.Time, "%H:%M")
copy1%>%group_by(GM)%>%
summarise(mean(copy1$Avg.Start.Time,na.rm=T))
但得到這樣的:
Error: column 'Avg.Start.Time' has unsupported type : POSIXlt, POSIXt
copy1$Avg.Start.Time <- hm(copy1$Avg.Start.Time)
mean(copy1$Avg.Start.Time,na.rm = T)
,但得到 「0」
任何想法如何,我可以計算Avg.Start.Time
每GM
:
我也使用lubridate
試過嗎?
感謝它不是一個有效的答案。兩次都返回相同的 – Shery
@Shery:對不起,只是在'summarise'中使用'copy1 $ Avg.Start.Time'而不是'Avg.Start.Time'的錯字。無論如何,其他答案會更好,因爲它會刪除日期。 – aichao
你可以使用'format(format =「%H:%M」)'格式化最後的結尾以及 – Shery