Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

How to sum a variable by group in R

Asked by Bhagwati Dubey Apr 22, 2021 739 views 1 answer
Share

About this question

I have a data frame of consisting two columns"Players" & "points"x<-data.frame(Players=c("Player1","Player2","Player3","Player2","Player3","Player1"),points=c(10,20,30,13,17,18))

Players points

1 Player1     10
2 Player2     20
3 Player3     30
4 Player2     13
5 Player3     17
6 Player1     18

I want to sort the data by players and sum the points:

Like this:

Players  x
1 Player1 28
2 Player2 33
3 Player3 47


Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.