Vector vs List in R

0 votes
I am new to R Programming and want to understand the difference between List and Vector Data Types. I know that both of them are linear data types but am not sure where to use List and where to use Vector.

I'd like to know the differences between List and Vector along with some use cases.
May 8, 2018 in Data Analytics by DataKing99
• 8,130 points
34 views

2 answers to this question.

0 votes

You are right in saying that both list and vector are linear data types, but the difference comes in the type of data they store.

A vector stores only homogenous data, while a list stores heterogenous data.

Below is an example to demonstrate that:

Vector:

names<-c("Raj","Amy","Sheldon","Leonerd")

This is a vector which comprises of only character elements.

List:

MixBag<-list(name="Raj",Indian=TRUE,Salary=64283)

Now, we have defined a list comprising of three elements of three different types.

answered May 8, 2018 by Bharani
• 4,550 points
0 votes

Well, you are right in  saying that both of them are linear data types, but the difference comes in the type of data they store.

A vector stores only homogenous data, while a list stores heterogenous data.

Below is an example to demonstrate that:

Vector:

names<-c("Raj","Amy","Sheldon","Leonerd")

This is a vector which comprises of elements of only one type;

List:

MixBag<-list(name="Raj",Indian=TRUE,Salary=64283)

Now, we have defined a list comprising of three elements, all of which are of different data types.

So, if you want to use a linear homogenous data types then you can go with Vector, but on the other hand if you want to use a linear heterogenous data type then you can use a list.
answered May 8, 2018 by anonymous

Related Questions In Data Analytics

0 votes
0 answers

Slicing a list using an index vector in r

How to slice a list using an ...READ MORE

Oct 9 in Data Analytics by anonymous
• 2,150 points
12 views
0 votes
1 answer

reverse a list or vector in R

@ch, Use rev function to reverse R objects ...READ MORE

answered 3 days ago in Data Analytics by Cherukuri
• 27,960 points
10 views
0 votes
1 answer

How to join two tables (tibbles) by *list* columns in R

You can use the hash from digest ...READ MORE

answered Apr 5, 2018 in Data Analytics by kappa3010
• 2,020 points
60 views
0 votes
2 answers

How to use group by for multiple columns in dplyr, using string vector input in R?

data = data.frame(   zzz11def = sample(LETTERS[1:3], 100, replace=TRUE),   zbc123qws1 ...READ MORE

answered Aug 5 in Data Analytics by anonymous
3,143 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
105 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
134 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points
78 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
84 views
0 votes
1 answer

How can I delete multiple values from a vector in R?

The %in% operator tells  which elements are ...READ MORE

answered Apr 26, 2018 in Data Analytics by shams
• 3,580 points
215 views
0 votes
2 answers

Installing MXNet for R in Windows System

You can install it for python in ...READ MORE

answered Dec 3, 2018 in Data Analytics by Kalgi
• 41,590 points
364 views