Scenario: I have df "rating" several user attempts when passing the test. Each observation is an attempt with a user ID and rating. Some users may transfer their first attempt; some may take several; they get unlimited attempts. I want to find the average score for each user.
For instance:
userID = c(1:20, sample(1:20, 10, replace = TRUE))
score = c(rnorm(15, mean = 60, sd = 10), rnorm(8, mean = 70, sd = 5),
rnorm(7, mean = 90, sd = 2))
scores = data.frame(userID, score)
I need a data frame of end results, which is a list of unique user IDs with the average value of all their attempts (regardless of whether they tried once or several times).
Of all the stupid approaches I tried, the last was:
avgScores = aggregate(scores, by=list("userID"), "mean")
: " ".
( ), , , .