1

I have this numerical variable in a data frame in R:

> head(sdbone$ncorrectas)
[1] 29 14 21 12 17  6

Then, I try to convert it to a dummy variable based on the condition that if ncorrectas > 10 it should have the value 1, otherwise 0:

I tried the following code :

> sdbone$ncorrectas < - ifelse(sdbone$ncorrectas > 10,1,0)

However, the variable doesn't change at all. So what's wrong with my code? and How Can I convert it to a dummy variable as I want to ?

Jaap
  • 81,064
  • 34
  • 182
  • 193
CreamStat
  • 2,155
  • 6
  • 27
  • 43

1 Answers1

1

remove the space between < and - ;)

Also, instead of ifelse, use the following

 sdbone$ncorrectas <- as.numeric(sdbone$ncorrectas > 10)
Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178