Question:
I have anR
dataframe
with a column titled ‘Normalized Month‘ for different entities.
I am trying to evaluate average of the column ‘Oil_Prod‘ grouped by ‘Normalized Month’.
Hence, the final dataframe should have just two columns; ‘Normalized Month’ and associated mean of oil prod for that ‘Normalized Month’ value.Here is the code:
What I need is a dataframe with a below structure:
‘Normalized Month’ | ‘Mean’ |
1 value1
2 value2
3 value 3
dput
:Answer:
When you usemydf2$Oil_Prod
you are referencing the external data frame, not the one from the pipe. I think if you stop subsetting within your dplyr functions, things will work as expected:If you have better answer, please add a comment about this, thank you!