Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

R Get Count of Unique Column Values with Same but Lesser Other Column Values

$
0
0

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?
enter image description here

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))

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>