I have a dataset with 100 questions (below I have a subset with 3 questions). I want to replace all the answer IDs with the actual answers provided in the "answer" dataset. The final result is shown in the "result" data frame.
data
name q1 q2 q3
1 a 1 3 7
2 a 8 3 1
3 a 3 9 2
4 b 4 4 3
answer
id str
1 TRUE
2 FALSE
3 YES
4 NO
5 LESS
6 MORE
7 GREATER
8 LESS
9 NONE
10 DAILY
result
name q1 q2 q3
1 a TRUE YES GREATER
2 a LESS YES TRUE
3 a YES NONE FALSE
4 b NO NO YES
We can
matchthe elements of the dataset ('df1', without the 'name' column) with the 'id' from 'answer' to get the numeric index (in this case we don't needmatch. In general, it may be safer to usematch) and get the corresponding 'str'.Or use
lookupfromqdapToolswhich can takekey/valuecolumns as a 'data.frame' (ie. 'answer') and get the matching valuesOr