Database Reference
In-Depth Information
[1] "own"
[[3]][[2]]
[1] "rent"
[[4]]
[1] 1 2 3 4 5
[[5]]
[,1] [,2] [,3]
[1,] 1 5 3
[2,] 3 0 3
[3,] 3 4 3
In displaying the contents of
assortment
, the use of the double brackets,
[[]]
,
is of particular importance. As the following R code illustrates, the use of the single
set of brackets only accesses an item in the list, not its content.
# examine the fifth object, M, in the list
class(assortment[5])
# returns "list"
length(assortment[5])
# returns 1
class(assortment[[5]])
# returns "matrix"
length(assortment[[5]])
# returns 9 (for the 3x3 matrix)
As presented earlier in the data frame discussion, the
str()
function offers details
about the structure of a list.
str(assortment)
List of 5
$ : chr "football"
$ : num 7.5
$ :List of 2
..$ : chr "own"
..$ : chr "rent"
$ : int [1:5] 1 2 3 4 5
$ : num [1:3, 1:3] 1 3 3 5 0 4 3 3 3
Factors
Factors were briefly introduced during the discussion of the
gender
variable in
the data frame
sales
. In this case,
gender
could assume one of two levels:
F
or
M
. Factors can be ordered or not ordered. In the case of
gender
, the levels are not
ordered.