Thursday, July 30, 2015

R programming - Lists

Refer index page for R at the following URL:
http://mylearningcafe.blogspot.in/2015/07/r-programming-index-page.html 


What are lists?
Lists are similar to vectors (list of data) but they have an advantage over vector in terms of the data type.

Vectors store data types of same form (e.g you could have a vector of numbers or vector of characters).
In a List, you could have various data types and also store another list or a data frame within it.

How to create a list?
mylist<-list(element1,element2,element3...)

We had created a data frame x in the last chapter (http://mylearningcafe.blogspot.in/2015/07/r-programming-data-frames.html).

We shall add that data frame to a list




In the above image, you can see that when we print a list, we can see the number of elements being displayed. In the above one, we created a list containing a number, a character, a vector and a data frame.

If you want to access the data of a specific element, use listname[[element_id]].
You need to use double square brackets [[ ]]



How to find the number of elements in a list?
Use the length(list_name) function

Refer index page for R at the following URL:
http://mylearningcafe.blogspot.in/2015/07/r-programming-index-page.html

No comments:

Post a Comment