I have a large vector of many values. I also have a table that shows what each of those values should be converted to. I know how to do this for one value of a vector at a time using gsub, but I'm not sure how to do this for all values simultaneously. Essentially, I want to take a vector, reference a datatable to figure out what each item of that vector should be converted to, and convert it.
Example:
test <- data.frame(Name = c(rep("TestA", 3), rep("TestB", 4), rep("TestC", 2)))
conversion <- data.table(Original = c("TestA", "TestB", "TestC"), New = c("380", "JK", "LOL"))
test
Name
1 TestA
2 TestA
3 TestA
4 TestB
5 TestB
6 TestB
7 TestB
8 TestC
9 TestC
conversion
Original New
1: TestA 380
2: TestB JK
3: TestC LOL
What I want:
Name NewName
1 TestA 380
2 TestA 380
3 TestA 380
4 TestB JK
5 TestB JK
6 TestB JK
7 TestB JK
8 TestC LOL
9 TestC LOL