0

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?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Umair Rafique
  • 108
  • 1
  • 9
  • 6
    The answer depends on the specific structure of `outcomedata`, so it would help if you provide a [reproducible example](https://stackoverflow.com/q/5963269/271616). – Joshua Ulrich Jun 23 '17 at 16:11
  • They should both work if `outcomedata` is a dataframe and `outcomeval` is a single value, as you suggest. Can you post a reproducible example? – Andrew Gustar Jun 23 '17 at 16:20

0 Answers0