0

For my data frame, which I'll call "data"

Class | Score
A     | 15
A     | 22
A     | 18
B     | 18
B     | 25
B     | 27

I'm trying to create a new column, which would basically be Score Divided By Class Average. I'm hoping to do this in as few lines as possible. Is it possible to do this in one or two lines of code and have it calculate the new column for a much larger data frame (ex: 100 rows).

  • 1
    See [here](http://stackoverflow.com/questions/21982987/mean-per-group-in-a-data-frame) and [here](http://stackoverflow.com/questions/7976001/adding-a-means-column-into-data-frame) for some ideas – David Arenburg Mar 15 '16 at 21:42
  • Thanks. I tried multiple searches but couldn't quite find what I was after. Looks like "mean per group" is the magic word I needed. – Matthew Rittinghouse Mar 15 '16 at 21:44
  • Please choose which one suits you better- the aggregation one or the creating a new column one, so I could close this. – David Arenburg Mar 15 '16 at 21:46
  • I am still trying to write out the code I need, but I'll close this with the solution that worked for me in just a few moments after I get it written down. – Matthew Rittinghouse Mar 15 '16 at 21:46

0 Answers0