R 中的向量与数据帧

发布于 2024-08-22 01:32:35 字数 39 浏览 3 评论 0原文

R 中的向量和数据框有什么区别?什么情况下向量应该转换为数据帧?

What is the difference between a vector and a data frame in R? Under what circumstances vectors should be converted to data frames?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半岛未凉 2024-08-29 01:32:35

向量有 1 维,而数据框有 2 维。我想不出将单个向量转换为数据框的充分理由。当您有多个向量时,通常会出现这个问题。

更好的问题是数据框和矩阵之间的区别是什么:数据框的每一列可以有不同的数据类型,而矩阵都是一种数据类型。在幕后,数据帧实际上是每个索引处具有相等长度向量的列表。

A vector has 1 dimension while a data frame has 2. I can't think of a good reason to convert a single vector into a data frame. That question generally arises when you have multiple vectors.

A better question is what is the difference between a data frame and a matrix: a data frame can have different data types for each column, while a matrix is all one data type. Behind the scenes, a data frame is really a list with equal length vectors at each index.

柏拉图鍀咏恒 2024-08-29 01:32:35

另一个值得注意的要点是,运行代码时,矩阵上的操作(大多数时候)比数据帧上的操作快得多。

塔尔

Another good point to note is that when running code, operations on matrixes are (most of the time) much faster then on data frames.

Tal

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文