my_diamonds <- diamonds %>% mutate(log_price = log(price))
my_diamonds %>%
+ group_by(cut) %>%
+ summarise(mean_log_exp = mean(log_price) %>% exp)
# A tibble: 5 x 2
cut mean_log_exp
<ord> <dbl>
1 Fair 3273.
2 Good 2547.
3 Very Good 2437.
4 Premium 2838.
5 Ideal 2079.
> my_diamonds %>%
+ group_by(cut) %>%
+ summarise(mean_price = mean(price))
# A tibble: 5 x 2
cut mean_price
<ord> <dbl>
1 Fair 4359.
2 Good 3929.
3 Very Good 3982.
4 Premium 4584.
5 Ideal 3458.
Why are these two outputs different? I expected both sets of numbers to be the same. In the first block I take the mean of the log of price for each cut then back transform to original scale with exp.
In the second block I skip the log transformation entirely. Since in the previous block I log and then unlog with exp, I expected the two sets of numbers to match.
Where have I misunderstood? Why don't the two sets of numbers match?