• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: dplyr (R) – Average of a column per group

Resolved: dplyr (R) – Average of a column per group

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have an R 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:
Instead of getting mean for each Normalized Month, I am getting a single value of mean.
What I need is a dataframe with a below structure:
‘Normalized Month’ | ‘Mean’ |
1 value1
2 value2
3 value 3
dput:

Answer:

When you use mydf2$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!

dplyr r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Resolved: PostgreSQL resample 1 minute OHLCV candle data into 5 minute OHLCV candle data

27/03/2023

Resolved: How do I navigate a table without any easily accessible distinctions?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.