Reputation: 3394
Ciao,
Here is my replicating example.
have <- data.frame("STUDENT"=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5),
"CLASS"=c(10,10,10,30,30,30,50,50,50,70,70,70,90,90,90),
"SCORE"=c(1:15))
want <- data.frame("STUDENT"=c(101,101,101,102,102,102,103,103,103,104,104,104,105,105,105),
"CLASS"=c(1,1,1,3,3,3,5,5,5,7,7,7,9,9,9),
"SCORE"=c(1:15))
So I want to basically generate a different order sequence of numbers for STUDENT and CLASS. In other words I want to recode STUDENT and CLASS so they are in a specific sequential order.
What I tried to do was
have %>% group_by(id) %>%
mutate(1=10,2=30)
but this is tedious and also does not work. Thanks a bunch!
Upvotes: 1
Views: 279
Reputation: 887691
We can try
have %>%
mutate(STUDENT = factor(STUDENT, labels = 101:105),
CLASS = substr(CLASS, 1, 1))
Upvotes: 1