WHAT IS LIST
A list is an object which can store any object of any dimension.
A list can store a vector, matrix, array, data frame or list inside it. There is no limitation of size. A list will return a list when accessed by single square bracket. i.e [ ]. But when accessed via [[ ]], then it simplifies the output i.e we get output in the form of a vector or matrix. (in the form it was inserted in list)
METHOD OF CREATION
##A list can be created by list function()
l1<-list(name="Amy",num=1001,marks=c(70,75,80,68,79),mat=matrix(1:10,2,5))
l2<-list(name="Sam",num=1001,marks=c(56,78,76,69,89),mat=matrix(1:10,2,5))
l3<-list(name="Dan",num=1001,marks=c(69,86,75,87,65),mat=matrix(1:10,2,5))
## we have created three list, each one with four elements, name, number, and marks and at. Name is character type, num is a number, marks is a vector and mat is a matrix. It is like a structure which helps to store different data types in one place. Now we can make a composite list consisting of above three list.
l<-list(Amy=l1,Sam=l2,Dan=l3)
ACCESSING LIST
l1[1] ## return first element of list l1 in the form of list.
$name
[1] "Amy"
l1[2] ## return second element of list l1in the form of list.
$num
[1] 1001
l1[3] ## return third element of list l1 in the form of list.
$marks
[1] 70 75 80 68 79
## Now if we want to access the first element of marks( marks is a vector). Then first of all we have to use [[]]. By placing [[3]] output get simplified and we will get a vector. Now by placing another set of square bracket with element number 1,we will get first element of third element of list.
l1[[3]] ## return third element of list in the form of vector.
[1] 70 75 80 68 79
l1[[3]][1] ## return first element of third element of list in the form of vector.
[1] 70
l1[[4]] ## return fourth element of list in the form of matrix.
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10
A list is an object which can store any object of any dimension.
A list can store a vector, matrix, array, data frame or list inside it. There is no limitation of size. A list will return a list when accessed by single square bracket. i.e [ ]. But when accessed via [[ ]], then it simplifies the output i.e we get output in the form of a vector or matrix. (in the form it was inserted in list)
METHOD OF CREATION
##A list can be created by list function()
l1<-list(name="Amy",num=1001,marks=c(70,75,80,68,79),mat=matrix(1:10,2,5))
l2<-list(name="Sam",num=1001,marks=c(56,78,76,69,89),mat=matrix(1:10,2,5))
l3<-list(name="Dan",num=1001,marks=c(69,86,75,87,65),mat=matrix(1:10,2,5))
## we have created three list, each one with four elements, name, number, and marks and at. Name is character type, num is a number, marks is a vector and mat is a matrix. It is like a structure which helps to store different data types in one place. Now we can make a composite list consisting of above three list.
l<-list(Amy=l1,Sam=l2,Dan=l3)
ACCESSING LIST
l1[1] ## return first element of list l1 in the form of list.
$name
[1] "Amy"
l1[2] ## return second element of list l1in the form of list.
$num
[1] 1001
l1[3] ## return third element of list l1 in the form of list.
$marks
[1] 70 75 80 68 79
## Now if we want to access the first element of marks( marks is a vector). Then first of all we have to use [[]]. By placing [[3]] output get simplified and we will get a vector. Now by placing another set of square bracket with element number 1,we will get first element of third element of list.
l1[[3]] ## return third element of list in the form of vector.
[1] 70 75 80 68 79
l1[[3]][1] ## return first element of third element of list in the form of vector.
[1] 70
l1[[4]] ## return fourth element of list in the form of matrix.
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10
This comment has been removed by the author.
ReplyDeleteI think this is one of the best posts on this topic. I am very happy to see your amazing post and thank you for your sharing with us. I like a more advanced level of information from your post and please keep it up...
ReplyDeleteSAS Training in Chennai
SAS Course in Chennai
Social Media Marketing Courses in Chennai
Tableau Training in Chennai
Html5 Training in Chennai
Node JS Training in Chennai
Informatica Training in Chennai
SAS Training in Adyar
SAS Training in Velachery
Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
ReplyDeleteJava Training in Chennai
Java Course in Chennai
Angularjs Training in Chennai
Selenium Training in Chennai
German Classes in Chennai
Java Training in Anna Nagar
I would like to thanks for your comprehensive article and these concepts are very helped to increase my knowledge. I hope more unique information from your post...
ReplyDeleteExcel Training in Chennai
Advanced Excel Training in Chennai
Excel Advanced course
corporate training in chennai
Embedded System Course Chennai
Linux Training in Chennai
Excel Training in Chennai
Advanced Excel Training in Chennai
virtual event platform The venue infrastructure must be able to manage multiple video streams as well as online connections for attendees. It’s essential to make sure the venue has the bandwidth and tech support capabilities required. thank you messages, funny fish and son in law birthday wishes
ReplyDelete