I have a data.frame that contains two columns that I want to group and sum the direct labor for employees.

Employees   Actual work
Joe Smo      8
Joe Smo      7
Joe Smo      5
Sam Adams    7
Sam Adams    5
Sam Adams    3

The desired outcome is

Joe Smo      20
Sam Adams    15

Here is the code I used that doesn't work.

aggregate(directLaborNov18[c('Employee')], directLaborNov18['Actual_work'], sum)

1 Answer 1


You were very close. Just switch the first two input arguments.

> aggregate(directLaborNov18['Actual_work'], directLaborNov18[c('Employee')],  sum)
   Employee Actual_work
1   Joe Smo          20
2 Sam Adams          15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.