in R Language by
Q:
Ungroup in R Language

1 Answer

0 votes
by

Last but not least, you need to remove the grouping before you want to change the level of the computation.

# Ungroup the data
data % > %
	filter(HR > 0) % > %
	group_by(playerID) % > %
	summarise(average_HR_game = sum(HR) / sum(G)) % > %
	ungroup() % > %
	summarise(total_average_homerun = mean(average_HR_game))

Code Explanation

  • filter(HR >0) : Exclude zero homerun
  • group_by(playerID): group by player
  • summarise(average_HR_game = sum(HR)/sum(G)): Compute average homerun by player
  • ungroup(): remove the grouping
  • summarise(total_average_homerun = mean(average_HR_game)): Summarize the data
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

0 votes
asked Nov 14, 2019 in R Language by MBarbieri
0 votes
asked Nov 14, 2019 in R Language by MBarbieri
...