官术网_书友最值得收藏!

How to do it…

Let's perform the following steps to create a list:

  1. The list() R function is used to create a list object. The dimension of a list could be any, and it can contain heterogeneous objects. To create a list called listA, execute the following code:
        listA <- list(cVec, nVec, Lvec, matA, datA, arrayA)
  1. The list could be a named list or without a name. To create a named list, the syntax is similar to the creation of a named vector. Here is an example:
        listB <- list(vector1 = cVec, vector2 = nVec, vector3 = Lvec,  
matrix1 = matA, data1 = datA, array1 = arrayA)
  1. The list preserves the original properties of the elements. To check the properties at a glance, you can use the str() function as follows:
        str(listA)
str(listB)

The preceding function will then provide the output of the number of elements of the list, data types of each of the components, and the name of each component (if there is any), along with few values of the components, as follows:

        > str(listA)
List of 6
$ : chr [1:4] "Cricket" "Football" "Basketball" "Rugby"
$ : int [1:10] 1 2 3 4 5 6 7 8 9 10
$ : logi [1:4] TRUE FALSE FALSE TRUE
$ : num [1:2, 1:2] 1 1 1 1
$ :'data.frame': 5 obs. of 3 variables:
..$ ID : int [1:5] 1 2 3 4 5
..$ hourSpetOnInternet: num [1:5] 5 3 4 1 2
..$ GENDER : Factor w/ 2 levels "F","M": 2 1 1 2 1
$ : int [1:2, 1:2, 1:4] 1 2 3 4 5 6 7 8 9 10 ...
主站蜘蛛池模板: 白河县| 白河县| 平陆县| 桂林市| 中宁县| 贵溪市| 固原市| 开鲁县| 嫩江县| 开封县| 禹州市| 宝鸡市| 岫岩| 凌海市| 浑源县| 专栏| 巴彦淖尔市| 十堰市| 监利县| 南昌市| 汾西县| 刚察县| 娱乐| 米林县| 潜山县| 芮城县| 大新县| 新郑市| 平山县| 康保县| 独山县| 沂源县| 宜兰市| 桐柏县| 广西| 霍山县| 山阳县| 乌拉特前旗| 株洲县| 苏尼特左旗| 灵寿县|