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

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
主站蜘蛛池模板: 韩城市| 讷河市| 桂阳县| 靖边县| 金坛市| 太仓市| 湖州市| 会同县| 思茅市| 双柏县| 长丰县| 中西区| 阜南县| 玉田县| 馆陶县| 乡宁县| 云南省| 黑龙江省| 郎溪县| 阳山县| 湘潭市| 太仓市| 邯郸市| 工布江达县| 泗水县| 灌南县| 新乐市| 盈江县| 隆子县| 拜泉县| 济源市| 衡水市| 潮安县| 重庆市| 毕节市| 武夷山市| 奉节县| 巴彦淖尔市| 望都县| 监利县| 广平县|