I am working with two dataframes. One is a raw data that recorded the respondent's response from the survey (they had to choose one choicest among three) so it indicates from 1-3. The second data frame is to organize the result from the first d.f. What I need is to drag the result from the first d.f for each Trial and indicate in the second d.f.
I am going to create a new column 'chosen' in the second d.f. For each trial, the chosen alternative from a respondent would have 1 in the 'chosen' column and 0 otherwise. I first need to find the chosen value that matches second d.f$trial with the digit that comes right after the column name "conjoint_full_info" in the first d.f. After finding the value, I need to indicate with "1" in "chosen" column the second d.f that which alternative is chosen. (By looking at the first d.f, in trial 1, the respondent chose alternative 1. So, indicate "1" in the chosen column along with column alternative=1 row. And the remaining 2 rows with "0") I am looking for a way to apply to every set below but I am not sure how to code this in an efficient way. Maybe using for loops? Sorry for the unclear explanations and thanks in advance!
First d.f
conjoint_full_info.2. conjoint_full_info.3. conjoint_full_info.4. conjoint_full_info.5.
1 2 2 2 1
conjoint_full_info.6. conjoint_full_info.7. conjoint_full_info.8. conjoint_full_info.9.
1 1 1 2 3
conjoint_full_info.10. Q16_1.2. Q16_2.2. Q16_3.2. Q16_4.2. Q16_1_TEXT.2. Q16_2_TEXT.2.
1 3
Second d.f
Ind Trial alternative price privacy battery stars chosen
1 R_2Xb32PAT3WjGBnc 1 1 2 3 1 1
2 R_2Xb32PAT3WjGBnc 1 2 3 1 2 2
3 R_2Xb32PAT3WjGBnc 1 3 1 2 3 3
4 R_2Xb32PAT3WjGBnc 2 1 1 2 2 1
5 R_2Xb32PAT3WjGBnc 2 2 2 3 3 2
6 R_2Xb32PAT3WjGBnc 2 3 3 1 1 3
7 R_2Xb32PAT3WjGBnc 3 1 3 1 3 1
8 R_2Xb32PAT3WjGBnc 3 2 1 2 1 2
9 R_2Xb32PAT3WjGBnc 3 3 2 3 2 3
10 R_2Xb32PAT3WjGBnc 4 1 1 1 1 2
11 R_2Xb32PAT3WjGBnc 4 2 2 2 2 3
12 R_2Xb32PAT3WjGBnc 4 3 3 3 3 1