如何基于值对表进行子集化并返回这些值?这仅返回索引:

with(chickwts, table(feed))
with(chickwts, table(feed)) > 11
which(with(chickwts, table(feed)) > 11)

输出
> with(chickwts, table(feed))
feed
   casein horsebean   linseed  meatmeal   soybean sunflower
       12        10        12        11        14        12
> with(chickwts, table(feed)) > 11
feed
   casein horsebean   linseed  meatmeal   soybean sunflower
     TRUE     FALSE      TRUE     FALSE      TRUE      TRUE
> which(with(chickwts, table(feed)) > 11)
   casein   linseed   soybean sunflower
        1         3         5         6

最佳答案

您需要使用计算值两次,因此使用中间变量非常有用:

x <- with(chickwts, table(feed))
x[x>11]
feed
   casein   linseed   soybean sunflower
       12        12        14        12

关于r - 如何在R中子集一个表对象?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12973151/

10-12 19:44