I tried going through the differences between the double square brackets [[]] extraction operator and the single square bracket extraction operator [] but couldn't understand what's causing the following behavior in my code, hence the question.
I have a data frame stored in a variable outcomedata
, and am aiming to remove the rows containing NA in the variable at column number stored in outcomeval
. So here's what's working:
outcomedata <- outcomedata[!is.na(outcomedata[[outcomeval]]),]
But when I tried using
outcomedata <- outcomedata[!is.na(outcomedata[, outcomeval]),]
, it wouldn't clean up those rows. Can somebody please tell me the difference between the two, what exactly is causing this behavior?