- Modern R Programming Cookbook
- Jaynal Abedin
- 149字
- 2021-07-08 09:48:34
How to do it…
Let's perform the following steps to create a list:
- 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)
- 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)
- 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 ...
推薦閱讀
- The Android Game Developer's Handbook
- C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)教程
- Production Ready OpenStack:Recipes for Successful Environments
- OpenNI Cookbook
- 零基礎(chǔ)輕松學(xué)SQL Server 2016
- 深入RabbitMQ
- Creating Stunning Dashboards with QlikView
- Learning Concurrency in Kotlin
- 區(qū)塊鏈技術(shù)與應(yīng)用
- Getting Started with React Native
- 快速入門與進(jìn)階:Creo 4·0全實(shí)例精講
- Getting Started with Polymer
- Visual C++從入門到精通(第2版)
- 視窗軟件設(shè)計(jì)和開發(fā)自動(dòng)化:可視化D++語(yǔ)言
- Mastering JavaScript