R 中的向量与数据帧
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
向量有 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.
另一个值得注意的要点是,运行代码时,矩阵上的操作(大多数时候)比数据帧上的操作快得多。
塔尔
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