I am working on an eye-tracking dataset want to assign values from existing columns to new columns, conditional on a second existing column.
I have columns: "targetlocation" with factors left and right, "right_looks" with numerical values, and "left_looks" with numerical values.
What I want to do is:
- Create new columns for "target_looks" and "distractor_looks" where:
- If “targetlocation” is right, then values from “right_looks” are assigned to “target_looks” and values from “left_looks” are assigned to “distractor_looks”
- If “targetlocation” is left, then values from “left_looks” are assigned to “target_looks” and values from “right_looks” are assigned to “distractor_looks”
I have tried creating first empty columns and then populating them, but maybe a mutate() or if_else() statement works better here. Are there any solutions for this?