R List

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


 
 

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I 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...
    SAS 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

    ReplyDelete
  3. 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.
    Java Training in Chennai
    Java Course in Chennai
    Angularjs Training in Chennai
    Selenium Training in Chennai
    German Classes in Chennai
    Java Training in Anna Nagar

    ReplyDelete
  4. 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

Translate

Monte Carlo Simulation with R

Stochastic Modeling A stochastic model is a tool for modeling data where uncertainty is present with the input. When input has cert...