【发布时间】:2011-06-20 04:18:28
【问题描述】:
我有一个包含一列的 data.frame,如下所示:
>d = data.frame(animal=c("horse","dog","cat"))
然后我通过排除也存在于向量中的所有项目来过滤它。例如:
> res = d[!(d$animal %in% c("horse")),]
> res
[1] dog cat
Levels: cat dog horse
>class(res)
[1] "factor"
这是怎么回事?
【问题讨论】:
-
另请注意,data.frame 中列的类不是“字符”,而是“因子”:
class(d[[1]])。