Hi,

I am new at coding so something as simple as doing a condition means seems hard.

In fact, what I am trying to do is to have the average consumption by hours (& for each year, but this is ok).

My data are like this :

I have a hard time finding the i e hours average/year.

I found this on the web :

mean(HQ$`2009`

|HQ$heure == 2, na.rm = TRUE)

[1] 1

Which 1 is not a possible value.

After digging on the web (conditional mean) I found the tidyverse, but I don't know if it's really this that I want :

hours_groups <- group_by(test_2, heure)

summarise(hours_groups, c_count_mean = mean(hours_groups, na.rm = TRUE), n = n())

The warning : In mean.default(hours_groups, na.rm = TRUE) :

argument is not numeric or logical: returning NA

I am a bit lost, because I would have been able to do it in 4 lines in stata. (with a for & if loop) :

for(h in hours) {

if (h == HQ$heure) {

mean(HQ$`2009`

, na.rm = TRUE)

}

}

Wich is not working, but it was my first try since it was my stata's intuitions.