Reputation: 10399
What is the difference between a vector and a data frame in R? Under what circumstances vectors should be converted to data frames?
Upvotes: 14
Views: 13847
Reputation: 25336
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
Upvotes: 5
Reputation: 100194
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.
Upvotes: 26