R Extract values from data frame with vectors
R Extract values from data frame with vectors I hope my question is not a duplicate, but I really couldn't find what I need. I dived in dplyr and even did the data.table course from DataCamp, but I can't fix it. Maybe overlooking something? I have this df: set.seed(1964) df<-data.frame(id = c( "XEY", "NZH", "DYE", "JNF", "LHH", "WNB"), q_1 = sample(5,6, replace = TRUE), q_2 = sample(5,6, replace = TRUE), q_3 = sample(5,6, replace = TRUE), q_4 = sample(5,6, replace = TRUE), q_5 = sample(5,6, replace = TRUE)) So my df looks like this: Next I have two vectors with id's (row-indicators) and q's (question numbers) like these: id <- c("XEY", "DYE", "JNF", "DYE", "XEY", "LHH", "WNB", "JNF" ) question <- c("val_1", "val_1","val_3","val_3"...