I have a dataframe in R with student IDs and questionIDs from a test. Students answer the questions sequentially but do not have to answer each question. For each student and question, what I'm trying to get is a count of how many unique students answered earlier questions (with questID< the current questID) as this student. Here is an example of the dataframe with some expected counts. As an example, studentID 1 on questID 3 has answered 2 previous questions (1 and 2) and there was two other unique students (studentID 2 and 3) who answered these questions. Any ideas how I can get these counts in R?
data
DF <- data.frame(studentID = c(rep(1, 4), rep(2,3), rep(3, 2)),
questID = c(1, 2, 3, 4, 1 , 2, 4, 2, 5))