I am trying to reassign raw scores. For more context, I had 10 people rate 100 items on a scale of 0-100. What I am wanting to do is re-group the raw scores into 1-5. So, for example, converting raw scores 0-20 = 1 ; 21-40 = 2 ; 41-60 = 3 ; 61-80 = 4 ; 81-100 = 5. I am new to Rstudio and am lost on how to go about this.
CodePudding user response:
We can use cut
as.integer(cut(scores, breaks = c(-Inf, 20, 40, 60, 80, 100)))
or with findInterval
findInterval(scores, c(0, 20, 40, 60, 80, 100))
data
set.seed(24)
scores <- sample(0:100, 20, replace = TRUE)
CodePudding user response:
You may divide the scores by 20 and use ceiling
.
df$group <- ceiling(df$score/20)
df
# people item score group
#1 1 3 90 5
#2 2 10 91 5
#3 3 2 69 4
#4 4 8 99 5
#5 5 6 57 3
#6 6 9 92 5
#7 7 1 9 1
#8 8 7 93 5
#9 9 5 72 4
#10 10 4 26 2
data
It is easier to help if you provide data in a reproducible format
set.seed(123)
df <- data.frame(people = 1:10, item = sample(10), score = sample(100, 10))