Categories

Nov 14, 2019 in R Language

Q: Ungroup in R Language

1 Answer

Nov 14, 2019

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

Madanswer
Nov 14, 2019 in R Language
Nov 14, 2019 in R Language
Nov 14, 2019 in R Language
...