mercredi 29 novembre 2017

Why does my If statement work in console but not during execution?

still learning how to use R, and I could use some input on why my if statement isn't being executed. I have a function that takes as one of its arguments a single character vector representing a health condition. If that condition reads "heart attack" I then want to do some stuff to a subset of my data. My if statement looks like this:

if (outcome=="heart attack"){
    Do some stuff to my data
    }

If I read and subset my data like I do in my script file, and then pretend the if condition has been satisfied and proceed on with "Do some stuff to my data" everything behaves how I expect it, but when I run the script, none of the code inside the if block gets executed and despite defining variables inside the if statement, my environment window stays empty. Any idea why this might be?

Aucun commentaire:

Enregistrer un commentaire