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