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,100 points
22 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
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,010 points
41 views
0 votes
1 answer

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

dplyr added versions for group_by. This allows you ...READ MORE

answered Apr 12, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 12, 2018 by CodingByHeart77 2,208 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,060 points

edited Apr 12, 2018 by nirvana 1,824 views
0 votes
1 answer
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,700 points
62 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,700 points
77 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,700 points
60 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,700 points
40 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
65 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
• 37,320 points
244 views