I have a dataframe like this one:
var1 <- c(1,2,0,1)
var2 <- c(2,0,3,1)
var3 <- c(10,5,10,4)
df <- data.frame(var1,var2,var3)
So, what I would like is to "average if" for column var3 values based on the values of each var so I end up with a df like this one:
var1 var2
6.33 8
Explanation: For var2 if I filter on values greater than 0, values of var 3 are (10,10 and 4) the average of those is 8. (24/3)
So basically I'm averaging the value of var3 for each var (var1 and var2) when they are greater than 0.
Thx,