0

i have a dataframe

  namer  None  namei  ...   None
  None   None  Na  ...   namej
   .
   .
  named  namev None   ...   Na

and i want to replace all Nones with 0 and everything else with 1 i tried to use lapply with the following function

 fu = function(x){
 if (x=="None")
     0
 else
     1}

but it throws an error, how can i fix this

user438383
  • 5,716
  • 8
  • 28
  • 43
Kaoutar
  • 345
  • 2
  • 10
  • More directly you're getting an error because you didn't include curly brackets in your `if () { outcome1 } else { outcome2 }` code. More generally, you don't need to do this because R vectorizes by default. you can just do `ifelse(x == "None", 0, 1)` – Phil Nov 12 '22 at 16:15
  • Or `+(x != "None")` should work. – Martin Gal Nov 12 '22 at 16:18

0 Answers0