I'm trying to automate creating variables indicating whether students' answer (variables beginning with l,m, f or g) to the questions (eg. variables starting in "test_") are correct or not. ie. This done by checking whether, for example, test_l1 == l1.
I cannot figure out how to do this other than using the index, but it's very tedious and creates a lot of codes.
Below is a toy dataset that mimics the structure of the actual dataset which has 4 different kinds of tests with 12 exercises each (test_l1 ~ test_l12, test_m1 ~ test_m12, test_f1~,test_g1~) and corresponding student responses (l1~l12, m1~m12, f1~, g1~). I would like to create 48 variables that are namely correct_l1 ~ correct_l12, correct_m1~, correct_f1~ etc.)
df<-data.frame(test_l1 = c(1,0,0), test_l2=c(1,1,1), test_m1 = c(0,1,0), test_m2=c(0,1,1), l1=c(0,1,0), l2=c(1,1,1), m1=c(1,1,1), m2=c(0,0,1))
Many thanks in advance!!!