English · PDF 338
tb <- tibble::tibble(x = 1:5, y = 5:1) typeof(tb) #> [1] "list" attributes(tb) #> $names #> [1] "x" "y" #> #> $class #> [1] "tbl_df" "tbl" "data.frame" #> #> $row.names #> [1] 1 2 3 4 5
传统的 data.frames 具有非常相似的结构:
df <- data.frame(x = 1:5, y = 5:1) typeof(df) #> [1] "list" attributes(df) #> $names #> [1] "x" "y" #> #> $row.names #> [1] 1 2 3 4 5 #> #> $class #> [1] "data.frame"
主要的区别在于类。tibble 的类中包含 "data.frame",这意味着 tibble 默认会继承常规数据框的行为。
tibble 或数据框与列表的区别在于,tibble 或数据框的所有元素必须是长度相同的向量。所有处理 tibble 的函数都会强制执行这一约束。