1

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!

1
  • 4
    have %>% mutate(STUDENT = STUDENT + 100, CLASS = CLASS / 10) ? Commented Sep 23, 2018 at 21:06

1 Answer 1

1

We can try

have %>% 
    mutate(STUDENT = factor(STUDENT, labels = 101:105),
           CLASS =  substr(CLASS, 1, 1))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.