R – Turorial II

[This article was first published on R – StudyTrails, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

 

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

Lists

  • 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
$a
[1] “apple”
$b
[1] “ball”
$c
[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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)