R – Turorial II

October 12, 2011

(This article was first published on R – StudyTrails, and kindly contributed to R-bloggers)


NOTE : This tutorial has been superseded by the exhaustive tutorials Here


  • Collection of Objects of same or mixed type.List may also contain vector or other lists.
  • Create a list using the funtion list().
  • The following example shows operations that can be performed on a list.

> alphabets=list(a=”apple”,b=”ball”,c=”cat”)
> alphabets
[1] “apple”
[1] “ball”
[1] “cat”

> alphabets[[1]]
[1] “apple”

> alphabets$a
[1] “apple”

> length(alphabets)
[1] 3

> alphabets[[“a”]]
[1] “apple”

  • Double brackets [[.]] are used for getting a single element. names are not returned.  single brackets [.]  can be used for subscripting.
  • When lists are formed from objects, the elements use to form the list are copied.
  • function c() can be used to combine lists to form an object of type list.

Data Frame

  • Lists having class ‘data.frame’ are called data frames.
  • the components of the list must be vectors, factors, numeric matrices, lists or other data frames. vector structures appearing as variables in the dataframe must all have same length. Matrix structures appearing as variables in the dataframe must all have same row size.
  • data frames can be created using function data.frame

To leave a comment for the author, please follow the link and comment on their blog: R – StudyTrails.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)