sách gpt4 ai đã đi

Khung dữ liệu có thể làm được điều gì mà tibble không thể làm được?

In lại 作者:行者123 更新时间:2023-12-03 17:18:53 29 4
mua khóa gpt4 Nike

Tidyverse 的粉丝经常给出使用小标题而不是数据框的几个优点。它们中的大多数似乎旨在保护用户免于犯错误。例如,与数据框不同,小标题:

  • 不需要 ,drop=FALSE不从数据中删除维度的论据。
  • 不会让$运算符对列名进行部分匹配。
  • 仅当输入向量的长度正好为 1 时才回收它们。

  • 我逐渐相信用小标题替换我所有的数据框。这样做的主要缺点是什么?更具体地说,数据框可以做什么而 tibble 不能?
    先声明一下,我不是在问 dữ liệu.bảng或对 Tidyverse 的任何大局反对。我严格询问小标题和数据框。

    1 Câu trả lời

    Từ the trouble with tibbles , 你可以阅读 :

    there isn’t really any trouble with tibbles


    然而,

    Some older packages don’t work with tibbles because of their alternative subsetting method. They expect tib[,1]to return a vector, when in fact it will now return another tibble.


    这是@Henrik 在评论中指出的。
    Ví dụ, chiều dài函数不会返回相同的结果:
    library(tibble)
    tibblecars <- as_tibble(mtcars)
    tibblecars[,"cyl"]
    #> # A tibble: 32 x 1
    #> cyl
    #>
    #> 1 6
    #> 2 6
    #> 3 4
    #> 4 6
    #> 5 8
    #> 6 6
    #> 7 8
    #> 8 4
    #> 9 4
    #> 10 6
    #> # ... with 22 more rows
    length(tibblecars[,"cyl"])
    #> [1] 1
    mtcars[,"cyl"]
    #> [1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4
    length(mtcars[,"cyl"])
    #> [1] 32
    其他例子:
  • base::reshape not working with tibbles

  • Invariants for subsetting and subassignment解释行为来自 tibbleKhác với dữ liệu.khung .
    这些限制是已知的,Hadley 在 interacting with legacy code 中给出的解决方案是:

    A handful of functions don’t work with tibbles because they expect df[, 1] to return a vector, not a data frame. If you encounter one of these functions, use as.data.frame() to turn a tibble back to a data frame:

    关于r - 数据框可以做什么而 tibble 不能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66466656/

    29 4 0
    行者123
    Hồ sơ cá nhân

    Tôi là một lập trình viên xuất sắc, rất giỏi!

    Nhận phiếu giảm giá Didi Taxi miễn phí
    Mã giảm giá Didi Taxi
    Giấy chứng nhận ICP Bắc Kinh số 000000
    Hợp tác quảng cáo: 1813099741@qq.com 6ren.com