I need to replace the values in the column with the corresponding row. In my searches, I came across similar questions with answers that exactly match what I'm looking for, but nothing that exactly matches my needs. Since I'm a newbie, this will help if you can explain how this code works.
I want to move from a dataset like this
A B C D
1 1 64 20 1
2 2 64 20 3
3 3 64 20 3
4 4 64 20 1
5 5 64 20 2
To a dataset that looks like this using key 1 = Apple, 2 = Blastoise, 3 = Carousel
A B C D
1 1 64 20 Apple
2 2 64 20 Carousel
3 3 64 20 Carousel
4 4 64 20 Apple
5 5 64 20 Blastoise
I understand that you can just use something like
df$D <- "label"
to change the values of a column.
However, I do not know how to get the "label" part to match the corresponding value.
Thank you in advance!