Hey! I am trying to combine the functions group_by with mutate but after the mutation, the result turns out not to be grouped.
These are the commands that I am using:
oecd_relative <- oecd_joined %>%
group_by(Year,country_code)%>%
mutate(PW_REAL_PPP = PW_REAL_PPP-mean(PW_REAL_PPP),PC_REAL_PPP = PC_REAL_PPP-mean(PC_REAL_PPP),REAL_PPP = REAL_PPP-mean(REAL_PPP))
Does anyone know what can be wrong? I want to group my mutation by year and country.
I think its a confusion of your involving grouped by and non grouped by elements in the same calculation.
Why not summarised oecd_joined by group_by and find the relevant means put them in means_ variables.
Then join the result to oecd_joined and substract each value from the mean
Thank you for your answer! Indeed that is a good thought. The reason why I focused on these two commands only is that my task allows me to only use these two commands so I am trying to see how to use them both in a correct way in order to get the result.
on second thoughts, there wouldnt seem to be anything especially wrong with the original approach.
I'm thinking that Ioanna might have suspected it wasnt working as it should , even though it was working fine.