I'd recommend creating a table with the respective variables and outcomes and then joining it to your table(s).
Reference Table Example
EDULEVEL cor
1 1 11
2 1ère 11
3 2 10
4 2nde 10
5 3ème 9
6 4ème 8
7 5ème 7
8 BAC 12
9 BAC+1 13
10 BAC+2 14
11 BAC+3 15
12 18 NA
13 Aucun NA
14 BAC+4 16
15 BAC+5 17
16 BEP 17
17 CAP 11
18 CE1 2
19 Certificat d'études 5
20 CM2 5
21 Doctorat 20
This is an example made from the information provided.
# Reference table is used as the primary table we will be joining the information to.
r1 <- base::data.frame(
EDULEVEL = c(
"1", "1ère", "2", "2nde", "3ème", "4ème", "5ème", "BAC", "BAC+1","BAC+2",
"BAC+3", "18", "Aucun", "BAC+4", "BAC+5", "BEP", "CAP", "CE1",
"Certificat d'études", "CM2","Doctorat"
),
cor = c(11, 11, 10, 10, 9, 8, 7, 12, 13, 14, 15, NA, NA, 16, 17, 17, 11, 2, 5, 5, 20)
)
# Second reference table with differing characteristics (EDULEVEL is unchanged)
r2 <- base::data.frame(
EDULEVEL = c(
"1", "1ère", "2", "2nde", "3ème", "4ème", "5ème", "BAC", "BAC+1","BAC+2",
"BAC+3", "18", "Aucun", "BAC+4", "BAC+5", "BEP", "CAP", "CE1",
"Certificat d'études", "CM2","Doctorat"
),
cor = c(20, 2, 3, 1, 29, 8, 3, 112, 14, 14, NA, NA, NA, NA, 1, 1, 1, 2, 5, NA, 20)
)
# Joining of two tables (r1 and r2).
r3 <- base::merge(x = r1, y = r2, by = "EDULEVEL", all = TRUE)