0

I'm trying to make some code that I can run in a variety of situations. What I've done is define criterion that I'd like to drop subjects if they meet it:

drop1 <- subset(data,data$fast > .20)

Now I'm trying to subset my main data set to exclude those subjects that met the criteria for drop1:

maindata <- subset(maindata,maindata$subject != drop1$subject)

My problem is that in this particular example, no subjects met this criteria. Thus, my main data set drops to 0 observations. How can I fix this so I can use this basic format regardless if subjects meet the condition or not?

THANKS!

user2917781
  • 273
  • 2
  • 10
  • 2
    Your question does not contain a [reproducible example](http://stackoverflow.com/q/5963269/4303162). It is therefore hard to understand your problem and give you an appropriate answer. Please make your data available (e.g. by using `dput()`) or use one of the example data sets in R. Also, add the minimal code required to reproduce your problem to your post. – Stibu Apr 12 '16 at 19:55
  • 1
    The point of using `subset` (rather than `[`) is that you don't need to use `data$column`. You can rewrite `drop1 <- subset(data, fast > .20)` and similarly below. *That being said*, `subset` is intended for interactive use. If you want "code that I can run in a variety of situations" you'd do well to heed the **Warning** section of `?subset` and use `[` instead. – Gregor Thomas Apr 12 '16 at 19:56
  • The subset argument to subset should not have the dataframe name in the expression. So it might be `subset(maindata, subject != drop1$subject)`, but it's also likely that drop1$subject might be of length greater than 1, so this may be safer: `subset(maindata, !subject %in% drop1$subject)` – IRTFM Apr 12 '16 at 19:57

0 Answers0