Creating a new variable based on a variable equaling multiple job titles

Beginner here. I'm curious on general strategies to create new variables based on another variable being equal to a certain character text (or if i can do it within the same data frame). I'm trying to group certain job titles into groups to compare scores on survey items. I'm semi-familiar with dplyr but it says operations are only possible for numeric types and only have the job titles in character form. Thanks!

Ex of what i tried:

sci <- dplyr::filter(engage, Job_Profile_Name =c( 'Data Scientist I', 'Data Scientist II', 'Data Scientist III',
'Data Scientist IV', 'Director, Data Science'))


Here is an example on how to summarise data if I understand your questions correctly:


#Generate dummy data

myData = data.frame(
  id = 1:10,
  job = paste0("DataScientist", sample(1:3, 10, replace = T)),
  value = runif(10)

#>    id            job     value
#> 1   1 DataScientist1 0.1765568
#> 2   2 DataScientist3 0.6870228
#> 3   3 DataScientist1 0.3841037
#> 4   4 DataScientist2 0.7698414
#> 5   5 DataScientist1 0.4976992
#> 6   6 DataScientist3 0.7176185
#> 7   7 DataScientist3 0.9919061
#> 8   8 DataScientist2 0.3800352
#> 9   9 DataScientist2 0.7774452
#> 10 10 DataScientist3 0.9347052

#Group by job and perform summary
myData %>% group_by(job) %>% summarise(val = sum(value))
#> # A tibble: 3 x 2
#>   job              val
#>   <chr>          <dbl>
#> 1 DataScientist1  1.06
#> 2 DataScientist2  1.93
#> 3 DataScientist3  3.33

Created on 2022-01-19 by the reprex package (v2.0.1)

Hope this helps,

Job_Profile_Name  %in% c( 'Data Scientist I', 'Data Scientist II', 'Data Scientist III',...)

may help.


Thanks! That returns True or False across the column now I just need to figure out how to only run an analyses based on the rows that are true

sci <- dplyr::filter(engage, Job_Profile_Name %in% c( 'Data Scientist I', 
  'Data Scientist II', 'Data Scientist III',
  'Data Scientist IV', 'Director, Data Science'))

gives only those rows, where Job_Profile_Name == TRUE.


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.