I have a data.frame wi开发者_StackOverflow社区th one column, like so:
>d = data.frame(animal=c("horse","dog","cat"))
then I filter it by excluding all items also present in a vector. e.g.:
> res = d[!(d$animal %in% c("horse")),]
> res
[1] dog cat
Levels: cat dog horse
>class(res)
[1] "factor"
What is going on here?
Welcome to R. You've just been bitten by the drop
annoyance: you need to explicitly tell R not to "drop to one-dimension":
res = d[!(d$animal %in% c("horse")), , drop = FALSE]
精彩评论