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,250 points
1,112 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,660 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

Slicing a list using an index vector in r

Use index within [] and provide an ...READ MORE

answered Nov 2, 2019 in Data Analytics by Cherukuri
• 33,030 points
10,772 views
0 votes
1 answer

reverse a list or vector in R

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

answered Oct 14, 2019 in Data Analytics by Cherukuri
• 33,030 points
6,237 views
0 votes
1 answer

What is the difference between list and vector in R?

The difference are - A list holds different ...READ MORE

answered Oct 29, 2019 in Data Analytics by Cherukuri
• 33,030 points
48,236 views
0 votes
0 answers

R function rep() in Python (replicates elements of a list/vector)

Each element of a vector is duplicated ...READ MORE

Jun 24, 2022 in Data Analytics by Sohail
• 3,040 points
1,356 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
2,268 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
1,963 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

edited Jun 9, 2020 by Gitika 1,202 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
1,400 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 27, 2018 in Data Analytics by shams
• 3,670 points
6,209 views
0 votes
2 answers

Installing MXNet for R in Windows System

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

answered Dec 4, 2018 in Data Analytics by Kalgi
• 52,350 points
2,491 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP