Mehper C. Palavuzlar
Mehper C. Palavuzlar

Reputation: 10399

Vector vs. Data frame in R

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

Answers (2)

Tal Galili
Tal Galili

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

Shane
Shane

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

Related Questions