I have a data.frame of numeric scores related to groups (y) measured across different factors (x) with resulting scores. Similar to the table below.
BU AUDIT CORC GOV PPS TMSC TRAIN
Unit1 2.00 0.00 2.00 4.00 1.50 2.50
Unit2 3.00 1.40 3.20 1.00 1.50 3.00
Unit3 2.50 2.40 2.80 3.00 2.75 2.50
Unit4 3.00 3.20 1.60 4.00 1.00 3.00
Unit5 2.00 2.80 2.00 2.00 3.00 2.50
Table is created like this
df %>%
group_by(BU, CC) %>% #BU = 'unit', CC = 'Control_Category
summarise(avg = mean(Score, na.rm = TRUE)) %>%
dcast(BU ~ CC, value.var = "avg") %>% print()
These numeric scores have a reference to a string value, like in the "table" below.
Control_Score > 3.499 ~ "Ineffective",
Control_Score > 2.499 & Control_Score <= 3.499 ~ "Marginally Effective",
Control_Score >= 1.500 & Control_Score <= 2.499 ~ "Generally Effective",
Control_Score > 0.000 & Control_Score <= 1.499 ~ "Highly Effective"
I tried a few apply functions to try and apply a comparison to the values. Also tried mutate with a case_when to no available.
In the end it would be ideal if the table looked like:
BU, AUDIT, CORC, GOV, PPS, TMSC, TRAIN
Unit1, Generally Effective, Highly Effective, etc, etc
Unit2, Marginally Effective, Highly Effective, etc, etc
Unit3, ...,...,...
Unit4, ...,...,...
Unit5, ...,...,...