【问题标题】:head and tail doesn't take negative number as argument for data.table?head 和 tail 不将负数作为 data.table 的参数?
【发布时间】:2013-09-21 08:49:15
【问题描述】:

为什么headtail 对于data.table 的工作方式不同?是设计的吗?

> head(data.frame(x=1:10), -2)
  x
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
> head(data.table(x=1:10), -2)
Error in seq_len(min(n, nrow(x))) : 
  argument must be coercible to non-negative integer
> tail(data.table(x=1:10), -2)
    x
1: NA
2: NA
3: NA
4: 10
> tail(data.frame(x=1:10), -2)
    x
3   3
4   4
5   5
6   6
7   7
8   8
9   9
10 10

【问题讨论】:

    标签: r data.table


    【解决方案1】:

    是的,这是以前报告过的,#2375。这现在已在 v1.8.11 中修复。来自NEWS

    head()tail() 现在可以正确处理负“n”值,#2375。感谢 Garrett See 的报道。当length(n) != 1 时也会导致错误。添加了测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 2016-10-30
      相关资源
      最近更新 更多