rdply和.id参数 - NULL不能像描述的那样工作

时间:2014-09-08 21:47:31

标签: r plyr

rdply包中plyr的文档说明.id参数:

 .id: name of the index column. Pass ‘NULL’ to avoid creation of
      the index column. For compatibility, omit this argument or
      pass ‘NA’ to avoid converting the index column to a factor;
      in this case, ‘".n"’ is used as colum name..

不幸的是,当我传递NULL时,所描述的行为似乎不起作用。考虑:

>rdply(20, mean(runif(20)))
   .n           V1
1   1 0.4202275122
2   2 0.5140590765
3   3 0.4201277295
4   4 0.4082553896
...

现在,我试图摆脱索引列:

> rdply(20, mean(runif(20)),.id=NULL)
Error in if (!is.na(.id)) names(labels) <- .id :
  argument is of length zero
In addition: Warning message:
In is.na(.id) : is.na() applied to non-(list or vector) of type 'NULL'

问题:如何使用.id参数来避免创建索引列,如文档中所述?

1 个答案:

答案 0 :(得分:5)

等到这个问题得到解决,或者使用现有列的名称.id

> rdply(20, mean(runif(20)), .id="V1")
       V1
1  0.4804
2  0.6339
3  0.5460
4  0.4473
5  0.4639
6  0.4759