IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> R语言列表和数据框 -> 正文阅读

[大数据]R语言列表和数据框

目录

1.列表

1.1创建

1.2 访问

1.2.1 下标访问

1.2.2 名称访问?

1.2.3?符号访问

?1.3 注意

2.数据框

2.1 创建

2.2 访问

2.2.1 下标访问

2.2.2 名称访问

2.2.3 符号访问

2.2.4 函数访问


1.列表

1.1创建

> a<-c(1:20)
> b<-matrix(1:20,4,5)
> mlist<-list(a,b)
> mlist
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14
[15] 15 16 17 18 19 20

[[2]]
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    5    9   13   17
[2,]    2    6   10   14   18
[3,]    3    7   11   15   19
[4,]    4    8   12   16   20

1.2 访问

1.2.1 下标访问

> mlist[1]
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14
[15] 15 16 17 18 19 20

> mlist[2]
[[1]]
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    5    9   13   17
[2,]    2    6   10   14   18
[3,]    3    7   11   15   19
[4,]    4    8   12   16   20

1.2.2 名称访问?

> state.center["x"]
$x
 [1]  -86.7509 -127.2500 -111.6250  -92.2992
 [5] -119.7730 -105.5130  -72.3573  -74.9841
 [9]  -81.6850  -83.3736 -126.2500 -113.9300
[13]  -89.3776  -86.0808  -93.3714  -98.1156
[17]  -84.7674  -92.2724  -68.9801  -76.6459
[21]  -71.5800  -84.6870  -94.6043  -89.8065
[25]  -92.5137 -109.3200  -99.5898 -116.8510
[29]  -71.3924  -74.2336 -105.9420  -75.1449
[33]  -78.4686 -100.0990  -82.5963  -97.1239
[37] -120.0680  -77.4500  -71.1244  -80.5056
[41]  -99.7238  -86.4560  -98.7857 -111.3300
[45]  -72.5450  -78.2005 -119.7460  -80.6665
[49]  -89.9941 -107.2560

1.2.3?符号访问

> state.center$x
 [1]  -86.7509 -127.2500 -111.6250  -92.2992
 [5] -119.7730 -105.5130  -72.3573  -74.9841
 [9]  -81.6850  -83.3736 -126.2500 -113.9300
[13]  -89.3776  -86.0808  -93.3714  -98.1156
[17]  -84.7674  -92.2724  -68.9801  -76.6459
[21]  -71.5800  -84.6870  -94.6043  -89.8065
[25]  -92.5137 -109.3200  -99.5898 -116.8510
[29]  -71.3924  -74.2336 -105.9420  -75.1449
[33]  -78.4686 -100.0990  -82.5963  -97.1239
[37] -120.0680  -77.4500  -71.1244  -80.5056
[41]  -99.7238  -86.4560  -98.7857 -111.3300
[45]  -72.5450  -78.2005 -119.7460  -80.6665
[49]  -89.9941 -107.2560

?1.3 注意

一个中括号和两个中括号的区别

一个中括号输出的是列表的一个子列表,两个中括号输出的是列表的元素

> class(mlist[1])
[1] "list"
> class(mlist[[1]])
[1] "integer"

?我们添加元素时要注意用两个中括号

2.数据框

2.1 创建

> state<-data.frame(state.name,state.abb,state.area)
> state
       state.name state.abb state.area
1         Alabama        AL      51609
2          Alaska        AK     589757
3         Arizona        AZ     113909
4        Arkansas        AR      53104
5      California        CA     158693
6        Colorado        CO     104247
7     Connecticut        CT       5009
8        Delaware        DE       2057
9         Florida        FL      58560
10        Georgia        GA      58876
11         Hawaii        HI       6450
12          Idaho        ID      83557
13       Illinois        IL      56400
14        Indiana        IN      36291
15           Iowa        IA      56290
16         Kansas        KS      82264
17       Kentucky        KY      40395
18      Louisiana        LA      48523
19          Maine        ME      33215
20       Maryland        MD      10577
21  Massachusetts        MA       8257
22       Michigan        MI      58216
23      Minnesota        MN      84068
24    Mississippi        MS      47716
25       Missouri        MO      69686
26        Montana        MT     147138
27       Nebraska        NE      77227
28         Nevada        NV     110540
29  New Hampshire        NH       9304
30     New Jersey        NJ       7836
31     New Mexico        NM     121666
32       New York        NY      49576
33 North Carolina        NC      52586
34   North Dakota        ND      70665
35           Ohio        OH      41222
36       Oklahoma        OK      69919
37         Oregon        OR      96981
38   Pennsylvania        PA      45333
39   Rhode Island        RI       1214
40 South Carolina        SC      31055
41   South Dakota        SD      77047
42      Tennessee        TN      42244
43          Texas        TX     267339
44           Utah        UT      84916
45        Vermont        VT       9609
46       Virginia        VA      40815
47     Washington        WA      68192
48  West Virginia        WV      24181
49      Wisconsin        WI      56154
50        Wyoming        WY      97914
> 

2.2 访问

2.2.1 下标访问

> state[1]
       state.name
1         Alabama
2          Alaska
3         Arizona
4        Arkansas
5      California
6        Colorado
7     Connecticut
8        Delaware
9         Florida
10        Georgia
11         Hawaii
12          Idaho
13       Illinois
14        Indiana
15           Iowa
16         Kansas
17       Kentucky
18      Louisiana
19          Maine
20       Maryland
21  Massachusetts
22       Michigan
23      Minnesota
24    Mississippi
25       Missouri
26        Montana
27       Nebraska
28         Nevada
29  New Hampshire
30     New Jersey
31     New Mexico
32       New York
33 North Carolina
34   North Dakota
35           Ohio
36       Oklahoma
37         Oregon
38   Pennsylvania
39   Rhode Island
40 South Carolina
41   South Dakota
42      Tennessee
43          Texas
44           Utah
45        Vermont
46       Virginia
47     Washington
48  West Virginia
49      Wisconsin
50        Wyoming

2.2.2 名称访问

> state["state.name"]
       state.name
1         Alabama
2          Alaska
3         Arizona
4        Arkansas
5      California
6        Colorado
7     Connecticut
8        Delaware
9         Florida
10        Georgia
11         Hawaii
12          Idaho
13       Illinois
14        Indiana
15           Iowa
16         Kansas
17       Kentucky
18      Louisiana
19          Maine
20       Maryland
21  Massachusetts
22       Michigan
23      Minnesota
24    Mississippi
25       Missouri
26        Montana
27       Nebraska
28         Nevada
29  New Hampshire
30     New Jersey
31     New Mexico
32       New York
33 North Carolina
34   North Dakota
35           Ohio
36       Oklahoma
37         Oregon
38   Pennsylvania
39   Rhode Island
40 South Carolina
41   South Dakota
42      Tennessee
43          Texas
44           Utah
45        Vermont
46       Virginia
47     Washington
48  West Virginia
49      Wisconsin
50        Wyoming

2.2.3 符号访问

> state$state.name
 [1] "Alabama"        "Alaska"        
 [3] "Arizona"        "Arkansas"      
 [5] "California"     "Colorado"      
 [7] "Connecticut"    "Delaware"      
 [9] "Florida"        "Georgia"       
[11] "Hawaii"         "Idaho"         
[13] "Illinois"       "Indiana"       
[15] "Iowa"           "Kansas"        
[17] "Kentucky"       "Louisiana"     
[19] "Maine"          "Maryland"      
[21] "Massachusetts"  "Michigan"      
[23] "Minnesota"      "Mississippi"   
[25] "Missouri"       "Montana"       
[27] "Nebraska"       "Nevada"        
[29] "New Hampshire"  "New Jersey"    
[31] "New Mexico"     "New York"      
[33] "North Carolina" "North Dakota"  
[35] "Ohio"           "Oklahoma"      
[37] "Oregon"         "Pennsylvania"  
[39] "Rhode Island"   "South Carolina"
[41] "South Dakota"   "Tennessee"     
[43] "Texas"          "Utah"          
[45] "Vermont"        "Virginia"      
[47] "Washington"     "West Virginia" 
[49] "Wisconsin"      "Wyoming" 

2.2.4 函数访问

> attach(state)
The following objects are masked from package:datasets:

    state.abb, state.area, state.name

> state.name
 [1] "Alabama"        "Alaska"        
 [3] "Arizona"        "Arkansas"      
 [5] "California"     "Colorado"      
 [7] "Connecticut"    "Delaware"      
 [9] "Florida"        "Georgia"       
[11] "Hawaii"         "Idaho"         
[13] "Illinois"       "Indiana"       
[15] "Iowa"           "Kansas"        
[17] "Kentucky"       "Louisiana"     
[19] "Maine"          "Maryland"      
[21] "Massachusetts"  "Michigan"      
[23] "Minnesota"      "Mississippi"   
[25] "Missouri"       "Montana"       
[27] "Nebraska"       "Nevada"        
[29] "New Hampshire"  "New Jersey"    
[31] "New Mexico"     "New York"      
[33] "North Carolina" "North Dakota"  
[35] "Ohio"           "Oklahoma"      
[37] "Oregon"         "Pennsylvania"  
[39] "Rhode Island"   "South Carolina"
[41] "South Dakota"   "Tennessee"     
[43] "Texas"          "Utah"          
[45] "Vermont"        "Virginia"      
[47] "Washington"     "West Virginia" 
[49] "Wisconsin"      "Wyoming"  

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-01-12 00:04:27  更:2022-01-12 00:04:42 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/25 12:52:39-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码