Question: I have a list of hours and I want to calculate the mean. The list looks like this:

```
mydata
       dawn  dusk
1      7:12 19:14
2      7:10 19:15
3      7:09 19:16
4      7:07 19:17
5      7:06 19:18
6      7:04 19:19
7      7:02 19:20
8      7:01 19:21

```

I tried in R but I couldn't find the way to calculate the mean, because the object is not numeric or logical. I can calculate the mean like this

```
mean(as.numeric(mydata$dusk)

```

but I cannot understand the result (57.5).
I tried in Excel but it is not working. If I try on a small sample like this (mydata) is working, but the data set has 500 rows and Excel shows a strange result (e.g.: in a list of dawn times, all comprised more or less between 05:00 AM and 08:00 AM, the result is 18:30. Same problem for dusk times). I don't know if the Excel problem depends from the time zone, so I would like to resolve in R.
Any suggestion? 
Regards,
Lisa

Answer: 
You can achieve that using `chron`
In your case, you need to get rid of factors as below:

```
mydata$dusk <- paste0(as.character(mydata$dusk), ":00")

```

Using `chron::times`

```
mean(chron::times(mydata$dusk))
[1] 19:17:30

```

Or as below

```
format(mean(strptime(mydata$dusk, "%H:%M:%S")), "%H:%M:%S")
[1] 19:17:30

```
You can also consider to use the lubridate package. The `hm` function can handle the hour:minute format. `period_to_seconds` and `seconds_to_period` can properly handle the time class.

```
library(tidyverse)
library(lubridate)

mydata2 <- mydata %>% 
  mutate_all(list(~hm(.))) %>%
  summarize_all(list(~seconds_to_period(mean(period_to_seconds(.)))))
mydata2
#          dawn        dusk
# 1 7H 6M 22.5S 19H 17M 30S

```

**DATA**

```
mydata <- read.table(text = "       dawn  dusk
1      '7:12' '19:14'
                     2      '7:10' '19:15'
                     3      '7:09' '19:16'
                     4      '7:07' '19:17'
                     5      '7:06' '19:18'
                     6      '7:04' '19:19'
                     7      '7:02' '19:20'
                     8      '7:01' '19:21'",
                     header = TRUE, stringsAsFactors = FALSE)

```