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

How it works…

The list() function works just like the concatenation function c(). It places each of the elements next to each other, while preserving their original data types and names of the objects. To get access to the component of a list, the simplest way is to use the double-square brackets along with a sequential index number of the element position as follows:

    listA[[1]]

The preceding function will give the output of the first element of the list, which is a character vector of four elements, as follows:

    [1] "Cricket"    "Football"   "Basetball" "Rugby"   

You can use the dollar $ operator next to the name of the list object to extract elements from the list. However, the list object must be a named list; otherwise the $ operator will not work. For example, to extract the data frame from listB, execute the following code snippet:

    listB$data1

> listB$data1
ID hourSpetOnInternet GENDER
1 1 5 M
2 2 3 F
3 3 4 F
4 4 1 M
5 5 2 F
主站蜘蛛池模板: 旺苍县| 怀安县| 射洪县| 阳春市| 义乌市| 岑巩县| 阿拉善左旗| 康保县| 平和县| 石门县| 陆川县| 开阳县| 沿河| 互助| 鲜城| 阿拉善左旗| 德安县| 武宣县| 贵港市| 绥宁县| 博客| 吉木萨尔县| 清水县| 乐亭县| 临高县| 阿克苏市| 建德市| 九江县| 廊坊市| 中超| 吉木乃县| 论坛| 江永县| 华安县| 达州市| 兴宁市| 井研县| 永安市| 噶尔县| 开封市| 迭部县|