I have a numeric vector, let's say something like:
x <- rep(1:6, 300)
What I would like to do is recode the vector, in place such that 6=1,5=2,4=3,3=4,2=5,1=6. I don't want to create a factor out of it.
Everything I have tried so far gives me the wrong counts because of the order, ie:
x[x == 6] <- 1
x[x == 5] <- 2 ## Lines that follow where x[x == 2] removes 5's entirely from counts.
Note: I'm aware of the car package, but would prefer to use base R for this problem.
Construct a map between the old and new values, and subset with the old,
(6:1)[x]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With