-2

I have a very large dataset with employers, employees and salaries. Each employee has a salary and is linked to an employer. Employers can have hundreds, even thousands of employees working for them. I want to find the average salary per employer. ie, I want to return an output with just 1 line per employer with an average salary based on all the employees they have. Thanks

Nottles82
  • 103
  • 7
  • 1
    Welcome on SO. Please read http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example . Maybe you should have also a look at `?aggregate`. – sgibb Mar 11 '14 at 17:33

1 Answers1

1

You can use aggregate for this:

aggregate(salaries, by = list(employers), FUN = mean)
Christopher Louden
  • 7,540
  • 2
  • 26
  • 29
  • Thanks - this works! as you can tell, I'm new to R and also these forums. apologises if I don't know the rules... – Nottles82 Mar 12 '14 at 10:27