Try
shop.data %>% group_by(hour) %>% mutate(profit= ifelse(is.na(profit), mean(profit, na.rm=TRUE), profit))
Or you can use replace
shop.data %>% group_by(hour) %>% mutate(profit= replace(profit, is.na(profit), mean(profit, na.rm=TRUE)))
source share