'Iterate over two dataframes to create a criterion column in R
I am looking to form a final data frame by iterating over two data frames.
The first df looks like this
employee_name <- c("rob", "peter")
employee_attribute1 <- c("10", "5")
employee_attribute2 <- c("5", "5")
employee_df <- data.frame(employee_name, employee_attribute1,employee_attribute2)
the second one looks like this. Employees can and do belong to multiple groups
employee_group <- c("1", "2","3" )
employee_attributes <- c("employee_attribute2", "employee_attribute2","employee_attribute1" )
group_att_mapping_df <- data.frame(employee_group,employee_attributes)
I would like to create a data frame like this. The rating condition is if employee attribute score in employee_df for the employee_attributes ( from group_att_mapping_df) = 10 then the rating is 1 else it is 2.
employee_group| employee_name | employee_rating
1 | Rob | 2
1 | Peter | 2
2 | Rob | 2
2 |Peter | 2
3 | Rob | 1
3 | Peter | 2
Need help writing valid R code to iterate over the two data frames. I will attach a screenshot of the loop I have written so far. Many thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
