views:

464

answers:

3

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

+7  A: 

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.

Shane
I was just going to ask you the difference between matrices and data frames. Thanks for the explanation.
Mehper C. Palavuzlar
+2  A: 

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

Tal Galili