-1

enter image description here

This is my current code for this image data[1:20,c("Job.Family", "Salaries", "Retirement")]. The goal here is to group all the same jobs in the Job.Family column together without loosing any data associated with it. So for example I would like to find out the sum of "Salaries" and "Retirement" for all those in the "Information System" Job.Family. Hopefully this makes sense.

Lee Kuo
  • 23
  • 5
  • don't attach your data by images, please read this to make people here understand and fix your problem https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Samet Sökel Sep 11 '21 at 00:22

1 Answers1

1

You are probably looking into some very basic subsetting and summarising operations here. I strongly recommend you study the dplyr package. Your example:

library(dplyr)

df %>% filter(Job.Family = "Information Systems") %>% 
       summarise(across(c(Salaries, Retirement), mean))

You may want to calculate this for all groups, as in:

df %>% group_by(Job.Family) %>% 
       summarise(across(c(Salaries, Retirement), mean))
GuedesBF
  • 8,409
  • 5
  • 19
  • 37