0

I have run into the following problem: due to a programming mistake, I had to change my rating scale from -4 to +4 to a scale from 0 to 9 temporarily. This results in 8 values in my data frame that I want to recode based on the ID that is defined in a different column.

id selfassessment
202 5
203 5
204 7
205 8
206 9
207 7
208 6

So for only those 8 rows in 'selfassessment' I want to change the values with 5 to 0, 6 to 1, 7 to 2, 8 to 3 and 9 to 4 without changing anything for the rest of the column. Can someone help me with this? Thank you!

1
  • There are 7 rows here... Commented Mar 25, 2019 at 11:09

2 Answers 2

1

You can use this code:

df$selfassessment <- ifelse(df$selfassessment<5, 0, df$selfassessment-5)

Sign up to request clarification or add additional context in comments.

3 Comments

thank you! This helps for the rows in question but overwrites everything else in the column. As I said, most of the columns were already coded in the right way. I only need to recode those specific rows.
Do you need to apply this formula for specific id'S or specific selfassesment interval ?
for specific id's
0

You can try:

df$selfassessment <- df$selfassessment - ifelse(df$selfassessment>=5, 5, 0)

1 Comment

glad to be of assistance! One thing: when you have a second, would you mind accepting the answer? Thanks.

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.