Scenario: I have a df, "scores" of multiple users attempt(s) at passing a test. Each observation is an attempt with the userID, and score. Some users may pass on their first attempt, some might take several; they get unlimited attempts. I want to find the average score for each user.
For example:
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 an end result data frame that is just a list of unique userIDs with the average of all of their attempts (whether they attempted once or several times).
Of all the dumb approaches I've tried, my most recent was:
avgScores = aggregate(scores, by=list("userID"), "mean")
and got the following error message: "arguments must have same length." I've also tried sorting and sub-setting (actual data frame has time stamps) and wiggling my nose and tapping my shoes together but I'm getting no where and this noob brain is fried.
THANK YOU