I had an original dataset that looks like this.:
> df.1
id score
1 13_B 1
2 13_C 4
3 133_D 5
4 141 2
5 145 3
6 143 4
7 12_B 6
8 12_C 7
9 12_D 9
I needed to do some process that needs all the id
s numeric therefore I recoded _B|_C|_D
into 1|2|3
.
After I finished some processed on the dataset having an extra group
column, Here is how my sample dataset looks like:
df.2 <- data.frame(id = c("131","132","133", "141", "145", "143", "121","122","123"),
score = c(1,4,5,2,3,4,6,7,9),
group = c(5,5,5,4,4,4,3,3,3))
> df.2
id score group
1 131 1 5
2 132 4 5
3 133 5 5
4 141 2 4
5 145 3 4
6 143 4 4
7 121 6 3
8 122 7 3
9 123 9 3
At this point, I need to convert the ids
back to the original for those items = c(12,13,15)
. So 15
is not in this dataset but need something that works globally. My desired output is:
> df.3
id score group
1 13_B 1 5
2 13_C 4 5
3 13_D 5 5
4 141 2 4
5 145 3 4
6 143 4 4
7 12_B 6 3
8 12_C 7 3
9 12_D 9 3
Any ideas?
Thanks!