forked from hcp4715/R4Psy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter_3.html
611 lines (468 loc) · 49.5 KB
/
chapter_3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>chapter_3.knit</title>
<meta charset="utf-8" />
<meta name="author" content="" />
<script src="libs/header-attrs-2.20/header-attrs.js"></script>
<link href="libs/remark-css-0.0.1/default.css" rel="stylesheet" />
<script src="libs/htmlwidgets-1.6.1/htmlwidgets.js"></script>
<link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="libs/datatables-binding-0.27/datatables.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<link href="libs/dt-core-1.12.1/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="libs/dt-core-1.12.1/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="libs/dt-core-1.12.1/js/jquery.dataTables.min.js"></script>
<link href="libs/crosstalk-1.2.0/css/crosstalk.min.css" rel="stylesheet" />
<script src="libs/crosstalk-1.2.0/js/crosstalk.min.js"></script>
<link rel="stylesheet" href="css/zh-CN.css" type="text/css" />
<link rel="stylesheet" href="css/Custumed_Style.css" type="text/css" />
</head>
<body>
<textarea id="source">
class: center, middle
<span style="font-size: 60px;">第三章</span> <br>
<span style="font-size: 50px;">如何导入数据</span> <br>
<br>
<span style="font-size: 30px;">胡传鹏</span> <br>
<span style="font-size: 20px;"> </span> <br>
<span style="font-size: 30px;">2023-03-07</span> <br>
<span style="font-size: 20px;"> Made with Rmarkdown</span> <br>
---
# 补充
## 使r语言的报错变为英文
- <font size = 5.5>在自己代码的开头输入如下命令,可以让当前的session报错为英文
```r
# set local encoding to English
if (.Platform$OS.type == 'windows') {
Sys.setlocale(category = 'LC_ALL','English_United States.1250')
} else {
Sys.setlocale(category = 'LC_ALL','en_US.UTF-8')
}
```
```
## [1] "LC_COLLATE=English_United States.1250;LC_CTYPE=English_United States.1250;LC_MONETARY=English_United States.1250;LC_NUMERIC=C;LC_TIME=English_United States.1250"
```
```r
# set the feedback language to English
Sys.setenv(LANG = "en")
```
---
# 回顾与问题
## 回顾
- # <font size = 5.5> 问卷数据:Human Penguin Project </font>
- # <font size = 5.5> 实验数据:Perceptual matching </font>
---
# 回顾与问题
## 回顾
- # <font size = 5.5> 问卷数据:Human Penguin Project </font>
- # <font size = 5.5> 实验数据:Perceptual matching </font>
<br><br>
## 问题
- # <font size = 5.5> 如何将这些数据“输入”到R里进行分析? </font>
# <font size = 4.5> 如何让R“识别”这些数据文件并读取它们? </font>
---
# 3.1 路径与工作目录
## 什么是工作目录?<br><br>
- # <font size = 5.5> 工作目录(working directory)是指用户当前的工作台(console)所进行交互的目录/文件夹。在此目录/文件夹中,你可在此通过相对路径访问文件或者文件夹。</font>
- # <font size = 5.5> 当你打开R时,R会自动设置一个默认的工作目录,通常为你的用户文件夹。</font>
- # <font size = 5.5> 当你打开R project时,R会自动将这个R Project所在的目录作为工作目录,通常为你的用户文件夹。</font>
---
# 3.1 路径与工作目录
## 什么是路径?<br><br>
- <font size=5.5> 路径是指文件(或文件夹)所在位置,包含绝对路径和相对路劲。</font>
- <font size=5.5> 绝对路径:文件在硬盘上的真实路径,如</font> <br><br>
<font size=5.5> `D:/Documents/r_course/chapter_3/data` </font>
<br><br>
- <font size=5.5>相对路径:相对于当前文件(或当前工作目录)的路径,如</font> <br><br>
<font size=5.5> "data" 或者 "./data" <br><br></font>
---
# 3.1 路径与工作目录
## 什么是路径?<br><br>
- <font size=5.5> 注意:Windows与MacOS/Linux的目录结构上有差异</font> <br><br>
<font size=5.5>**此时我们的工作路径为chapter_3文件夹,也被称之为母文件夹(patent directory),在工作路径之下的文件夹也被成为子文件夹(child directory)**
<br><br>
- 在数据分析时使用哪一种路径更好?</font>
---
# 3.1 路径与工作目录
## 获取及修改工作目录的基本操作
```r
# 查看当前工作目录
getwd()
```
```
## [1] "C:/Users/Pac.B/Desktop/test"
```
```r
# 修改当前工作路径
setwd("./picture/chapter3")
getwd()
```
```
## [1] "C:/Users/Pac.B/Desktop/test/picture/chapter3"
```
---
# 3.1 路径与工作目录
## Here包的使用
- <font size=5.5> Here是R的一个package,它可以帮助使用者方便快捷的获取路径</font><br>
<br>
- <font size=5.5> 请注意,here()获取的路径取决于你打开项目的位置</font><br>
<br>
- <font size=5.5> here()只能返回路径,并不能更改路径</font>
```r
# 将获取的路径储存到变量my.path中,方便调用
# 可以使用::来调用未加载包中的函数,推荐在少量调用时使用这种方式
here::here()
```
```
## [1] "D:/R assistant/PPT/chapter456/R_psy_class/chapter4"
```
---
# 3.1 路径与工作目录
## Here包的使用
```r
# 当我更改目录之后会出现什么情况?
setwd("./picture/chapter3")
getwd()
```
```
## [1] "C:/Users/Pac.B/Desktop/test/picture/chapter3"
```
```r
here::here()
```
```
## [1] "D:/R assistant/PPT/chapter456/R_psy_class/chapter4"
```
<font size=5.5>**不同的场合下选择适合的函数来简化你的代码**
---
# 3.1 路径与工作目录
## 需要注意在R中输入地址与Windows中地址栏的区别
```r
# r语言中的地址
first_path <- getwd()
cat(first_path,"\n")
```
```
## C:/Users/Pac.B/Desktop/test
```
```r
# Windows的地址
normalized_path <- normalizePath(first_path, winslash = "\\")
cat(normalized_path)
```
```
## C:\Users\Pac.B\Desktop\test
```
<font size=5.5>**因此注意不要直接复制Windows地址栏中的地址**
---
<br>
<br>
<br>
<br>
<br>
.center[ <font size=10>现在我们知道了工作目录和路径,看看我们的数据文件的绝对路径和相对路径是什么?</font> ]
---
# 3.2 读取数据
## 使用R语言读取数据<br><br>
- <font size=6>使用R读取数据,是处理数据的预备工作</font><br>
<span style="font-size: 20px;"> </span> <br>
- <font size=6>最好将数据放于工作目录下的子文件夹中</font><br>
<span style="font-size: 20px;"> </span> <br>
- <font size=6>通过相对路径读取数据,便于分享你的工作</font><br>
<span style="font-size: 20px;"> </span> <br>
---
# 3.2 读取数据
## 读取csv文件
```r
# 读取.csv类型文件
penguin.data <- read.csv('./data/penguin/penguin_rawdata.csv',
header = TRUE, sep=",",
stringsAsFactors = FALSE)
```
- <font size=5.5> './data/penguin/penguin_rawdata.csv' :表示csv文件的相对路径
- <font size=5.5> 'header = TRUE':表示文件中包含列名
- <font size=5.5> 'sep = ","':表示文件中数据之间用逗号分隔,这也是.csv文件的默认分隔方式
- <font size=5.5> 'stringsAsFactors = FALSE':表示读入的字符串数据不转化成 factors类,保持字符类
- <font size=5.5> 读取之后数据变量可以从Environment中找到,变量名为penguin.data </font>
---
# 3.2 读取数据
## 读取csv文件
```r
# 读取.csv类型文件
penguin.data <- read.csv('./data/penguin/penguin_rawdata.csv',
header = TRUE, sep=",",
stringsAsFactors = FALSE)
# 使用DT包中的datatable在ppt中展示表格
DT::datatable(head(penguin.data, 10),
fillContainer = TRUE, options = list(pageLength = 3))
```
<div class="datatables html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-0e54c6a6b81a4c12202c" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-0e54c6a6b81a4c12202c">{"x":{"filter":"none","vertical":false,"fillContainer":true,"data":[["1","2","3","4","5","6","7","8","9","10"],[1975,1995,1995,1988,1991,1995,1996,1973,1996,1996],[1,2,4,2,2,2,1,3,2,3],[1,2,1,3,1,3,1,3,3,3],[1,2,1,4,1,1,1,2,1,1],[2,2,2,5,5,3,1,3,3,2],[2,2,4,3,2,2,4,4,2,4],[1,2,1,4,2,1,1,4,2,1],[2,2,4,2,3,1,2,4,2,2],[2,2,1,4,4,2,1,4,2,4],[4,4,1,4,1,1,4,4,2,4],[1,2,2,3,1,2,2,5,2,1],[1,2,1,2,2,1,1,3,1,4],[2,2,1,2,1,2,2,2,2,1],[4,2,2,4,2,3,4,2,2,2],[3,2,1,2,4,4,3,3,4,3],[4,3,1,4,4,5,5,4,3,5],[2,2,1,3,2,4,5,1,2,4],[3.72222222222222,4.05555555555556,1.44444444444444,4.72222222222222,2.11111111111111,2,2.55555555555556,3.05555555555556,3.55555555555556,4.38888888888889],[6,0,0,2,0,0,null,0,0,0],[3.11111111111111,4.88888888888889,1.33333333333333,3.88888888888889,4.66666666666667,3.33333333333333,3.11111111111111,3.55555555555556,3.33333333333333,3.22222222222222],[3.44444444444444,2,2,3,1.77777777777778,2.44444444444444,3.77777777777778,3.33333333333333,1.88888888888889,4.22222222222222],[89,89,89,89,89,89,89,89,89,89],[3.27777777777778,3,1.61111111111111,3.94444444444444,4.94444444444444,3.77777777777778,6.44444444444444,3.22222222222222,4,5.27777777777778],[15,null,null,null,null,null,null,10,null,1],[1.63636363636364,2.18181818181818,2,3.27272727272727,2.18181818181818,1.72727272727273,1.72727272727273,3.54545454545455,2,2.63636363636364],[1,1,1,2,1,1,1,1,1,1],[5,6,1,3,1,1,2,3,4,5],[5,4,1,6,1,1,1,2,4,6],[3,2,1,6,1,1,4,3,4,6],[5,5,1,5,1,2,1,2,4,5],[5,5,1,4,1,2,4,3,4,4],[3,2,1,4,5,1,1,3,1,3],[1,3,1,3,2,1,2,3,4,5],[6,5,1,3,1,2,7,3,4,7],[5,2,1,4,7,6,1,3,4,3],[2,3,1,4,1,2,4,1,4,3],[6,7,1,6,6,2,2,5,2,6],[3,4,1,5,1,2,1,2,4,4],[3,3,1,6,2,4,2,5,4,4],[2,3,7,5,1,1,1,4,1,2],[3,4,1,5,2,2,1,5,4,1],[3,5,3,5,1,1,2,3,4,4],[6,5,1,6,2,3,6,3,4,7],[1,5,1,5,2,2,4,2,4,4],[2,3,2,5,1,5,7,3,4,5],[2,4,2,5,7,5,1,2,4,7],[5,3,2,5,2,4,6,4,4,5],[3,2,2,4,5,4,7,3,4,5],[3,2,2,3,2,3,7,3,4,6],[2,3,1,4,4,4,7,3,4,5],[5,3,1,6,2,3,7,4,4,6],[5,4,1,3,6,3,7,4,4,7],[3,5,1,3,7,1,7,4,4,7],[2,3,1,4,6,3,6,3,4,4],[4,2,2,5,6,6,6,3,4,4],[2,2,2,3,6,5,7,2,4,5],[3,4,1,4,7,4,7,2,4,3],[3,2,2,5,2,3,7,3,4,6],[4,3,3,3,7,4,6,3,4,5],[5,3,1,2,6,5,7,4,4,6],[4,3,1,3,6,3,7,6,4,5],[2,3,2,4,7,3,7,2,4,4],["9:23:38","9:23:26","8:57:08","8:55:14","8:54:35","8:39:12","8:32:08","8:28:57","8:28:03","8:25:57"],[3,2.2,1.2,3,2.6,3.6,3.8,2.4,2.6,3],[2,2,2,2,2,2,2,2,2,2],[0,0,12,0,5,0,null,1,0,2],[4,4,4,3,4,4,4,1,3,3],[4,5,1,5,5,4,5,3,3,4],[3,5,1,4,5,4,2,3,3,5],[4,5,4,5,5,4,4,2,4,3],[3,5,1,5,5,4,5,4,5,3],[3,5,1,4,4,4,2,3,4,4],[2,4,1,2,5,2,1,4,3,2],[4,5,1,2,4,2,5,5,2,2],[3,5,1,4,4,3,1,4,3,3],[2,5,1,4,5,3,3,4,3,3],[4,1,5,5,1,3,2,3,3,4],[4,2,6,4,1,3,2,3,3,5],[5,6,5,3,3,3,2,2,2,1],[4,2,4,1,2,2,2,2,1,3],[4,3,3,2,2,2,2,2,3,2],[1,2,1,2,2,4,2,3,3,3],[2,2,1,2,1,4,2,3,1,2],[17,28,24,19,29,33,53,17,17,19],[4.33333333333333,6.5,6.83333333333333,3.5,1.5,2,5.83333333333333,6.33333333333333,5.66666666666667,5.16666666666667],[2.27272727272727,2.63636363636364,2.18181818181818,2,1.90909090909091,2.45454545454545,2.81818181818182,2.54545454545455,1.81818181818182,3.90909090909091],[2,3,3,1,3,4,4,2,2,5],[2,2,4,1,2,4,4,3,3,4],[2,3,2,2,1,2,2,3,2,5],[4,3,4,3,4,4,2,2,2,4],[2,3,1,2,1,3,3,3,2,3],[2,2,1,2,1,1,2,2,1,3],[2,2,1,2,1,2,2,4,2,4],[2,3,3,1,1,1,2,3,2,3],[3,3,3,2,2,2,4,2,1,3],[2,3,1,4,2,1,2,1,1,4],[2,2,1,2,3,3,4,3,2,5],[4,2,1,2,2,3,3,3,3,4],[4,2,4,4,1,3,4,4,2,4],[2,2,1,3,1,2,5,3,1,2],[5,2,4,2,1,3,4,3,4,4],[2,2,1,3,1,2,1,2,3,5],[2,2,1,2,3,2,3,4,1,4],[4,2,1,3,2,2,5,3,1,5],[4,2,1,4,1,3,5,4,1,5],[4,2,4,4,4,2,4,4,1,5],[2,2,1,1,2,2,2,2,2,2],[2,4,2,4,3,5,2,1,3,3],[2,4,3,2,5,5,4,4,3,4],[2,4,3,1,5,5,2,5,5,5],[1,4,2,1,3,2,2,2,5,1],[1,4,4,2,5,3,1,2,5,2],[4,3,2,1,5,4,3,3,3,1],[2,4,4,2,5,3,2,3,4,2],[2,2,1,3,4,3,2,2,5,4],[5,4,3,4,4,5,4,4,3,3],[4,3,5,3,3,5,5,3,4,2],[3,4,4,2,4,5,3,2,2,5],[5,5,4,2,4,4,1,3,4,3],[4,4,4,2,4,3,2,2,2,2],[2.84615384615385,3.76923076923077,3.15384615384615,2.23076923076923,4.15384615384615,4,2.53846153846154,2.76923076923077,3.69230769230769,2.84615384615385],[1,1,1,2,1,1,2,1,1,2],[1,2,2,2,2,2,2,1,2,1],[2,1,1,1,2,2,2,4,2,2],[1,1,1,1,1,1,1,1,1,1],[null,null,null,null,null,null,null,null,null,null],[4,4,4,4,2,4,4,4,4,4],[4,4,4,4,2,4,4,2,4,4],[5,1,4,5,5,5,5,5,5,5],[null,null,4,null,null,null,null,null,null,null],[1,8,2,1,8,2,3,8,2,6],[null,6,2,null,5,1,2,3,2,3],[6,4,5,5,7,5,8,4,3,8],[3,1,5,1,3,5,8,4,2,8],[1,1,1,1,2,1,1,1,1,1],[null,null,null,null,8,null,null,null,null,null],[1,2,2,1,1,2,2,2,2,2],[null,8,8,null,null,8,8,8,8,8],[3,3,2,3,3,1,1,1,1,1],[2,8,1,8,1,null,null,null,null,null],[6,5,6,4,8,null,null,null,null,null],[1,3,1,1,1,8,6,4,1,3],[1,1,1,1,1,1,1,2,1,1],[null,null,null,null,null,null,null,2,null,null],[1,1,1,2,1,2,2,2,2,1],[" "," "," "," "," ","Rowing Club","University Friends","ODAA","Oxford Latin Speaking Society"," "],[" "," "," "," "," ","Rugby Club","Business Social"," ","Oxford Latin Conversation Society"," "],[" "," "," "," "," "," ","Lecturers/ Advisors"," ","Plato Reading Group"," "],[" "," "," "," "," "," ","Friends from home"," "," "," "],[" "," "," "," "," "," ","Neighbors"," "," "," "],[null,null,null,null,null,7,20,1,2,null],[null,null,null,null,null,7,15,null,4,null],[null,null,null,null,null,null,5,null,1,null],[null,null,null,null,null,null,9,null,null,null],[null,null,null,null,null,null,6,null,null,null],[6,6,7,2,1,1,6,6,7,7],[5,7,7,5,2,2,7,6,7,4],[5,6,7,3,2,3,5,7,6,5],[3,7,7,4,1,2,5,6,6,5],[2,6,7,5,2,2,6,7,5,5],[5,7,6,2,1,2,6,6,3,5],[4,6,6,4,1,2,5,6,3,4],[5,7,8,5,7,6,null,7,6,6],[1,2,3,1,2,4,null,2,2,3],[4,2,4,4,1,2,2,3,3,1],[4,4,5,2,1,4,4,2,5,4],[4,3,4,3,1,4,2,3,4,4],[5,3,4,3,4,4,4,4,2,4],[2,3,4,4,4,4,5,2,2,3],[2,4,4,3,1,3,4,3,1,3],[2,5,4,3,3,4,5,4,2,2],[2,2,4,3,4,3,5,3,2,4],[4,5,5,2,1,2,4,2,4,5],[2,3,2,2,1,4,1,4,4,5],[2,2,1,2,1,2,2,2,2,1],[1,2,2,2,4,4,4,2,2,2],[4,4,4,3,4,2,2,3,2,1],[5,4,2,3,2,4,3,4,4,4],[4,4,2,3,3,1,2,4,5,3],[2,3,4,4,4,5,5,4,4,4],[2,3,5,4,4,3,2,4,2,2],[4,3,4,2,4,3,4,3,3,2],[3,3,5,2,4,4,4,4,3,3],[2,3,1,3,5,4,1,3,2,4],[4,3,4,2,4,4,5,4,3,5],[3,3,5,4,4,3,2,2,3,3],[2,3,1,3,4,3,2,3,4,3],[3,3,1,4,1,2,2,2,3,3],[4,3,5,3,1,2,5,1,4,4],[3,3,3,2,1,3,3,2,3,3],[4,3,1,4,4,4,2,4,1,1],[4,5,4,2,1,3,1,4,4,5],[3,5,4,4,1,2,1,3,5,5],[3,2,2,4,4,2,5,2,2,4],[2,4,2,5,1,2,1,3,2,4],[4,3,1,2,4,2,5,1,1,4],[4,3,2,2,3,3,1,4,3,4],[1,4,3,4,4,2,1,3,2,2],[2,4,2,3,5,4,2,5,1,4],[2,4,2,4,5,4,4,4,2,4],[4,4,4,3,4,4,2,4,2,4],[3,4,2,4,4,4,4,5,5,1],[4,2,2,3,4,4,5,2,2,4],[5,3,3,2,4,2,2,2,2,4],[4,3,2,3,3,3,2,1,2,4],[4,3,5,2,4,4,4,4,4,4],[1,4,2,3,4,2,2,3,2,3],[1,2,2,4,4,2,1,2,1,2],[4,3,2,3,1,2,1,4,4,2],[4,4,4,2,1,4,1,4,3,3],[3,3,4,3,4,2,4,3,3,4],[1,2,5,4,4,2,1,2,1,2],[2,3,5,4,4,2,1,2,1,2],[4,3,5,4,4,4,3,3,3,4],[4,4,2,5,1,3,5,2,4,5],[2,4,5,3,1,2,5,4,2,4],[2,4,4,3,4,2,1,3,2,2],[4,3,4,3,5,2,4,4,2,4],[2,4,2,2,4,3,3,2,2,4],[2,4,1,2,4,2,2,2,2,2],[1,2,5,4,1,1,4,2,2,2],[3.07692307692308,2.46153846153846,2.38461538461538,2.84615384615385,2.53846153846154,2.07692307692308,1.53846153846154,3,2.61538461538462,3.15384615384615],[4,2,3,3,3,2,1,4,5,3],[2,3,3,3,4,2,2,3,2,4],[4,3,4,4,3,3,1,3,3,5],[4,3,1,2,2,2,2,3,2,4],[4,2,2,3,2,2,2,3,2,3],[3,2,1,2,1,2,2,3,2,1],[4,2,2,3,3,2,1,4,2,3],[3,2,2,2,2,2,1,4,3,4],[3,2,3,3,2,2,2,1,2,3],[2,3,3,3,3,2,1,3,4,3],[4,2,3,4,3,2,2,2,1,2],[3,4,4,3,5,4,4,4,5,4],[2,4,2,3,2,2,2,3,3,2],[1,2,2,2,3,2,1,3,3,4],[34.9,35.8,34,36.9,35.3,34.7,36,36.5,34.7,35.9],[35.9,36,36.2,37,36.1,36.4,36.3,36.6,36.3,36.3],[2,2,2,2,4,4,2,2,2,2],[35.4,35.9,35.1,36.95,35.7,35.55,36.15,36.55,35.5,36.1],[1,1,1,1,1,1,1,1,1,1],[-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667],[5,5,5,5,5,5,5,5,5,5],[1,1,1,1,1,1,1,1,1,1],[0.186319647739787,0.472682850177291,-1.77049556891649,1.0454092550523,-1.19776916404149,-1.29322356485399,-0.815951560791479,-0.386406757135223,0.0431380465210342,0.759046052614796],[-0.00190690952064737,-0.249805147204807,-1.48929633562561,0.593048860921336,1.48548251658431,0.44430991831084,2.82413300007877,-0.0514865570574791,0.642628508458168,1.7829604018053],["Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford"]],"container":"<table class=\"display fill-container\">\n <thead>\n <tr>\n <th> <\/th>\n <th>ď.żage<\/th>\n <th>ALEX1<\/th>\n <th>ALEX2<\/th>\n <th>ALEX3<\/th>\n <th>ALEX4<\/th>\n <th>ALEX5<\/th>\n <th>ALEX6<\/th>\n <th>ALEX7<\/th>\n <th>ALEX8<\/th>\n <th>ALEX9<\/th>\n <th>ALEX10<\/th>\n <th>ALEX11<\/th>\n <th>ALEX12<\/th>\n <th>ALEX13<\/th>\n <th>ALEX14<\/th>\n <th>ALEX15<\/th>\n <th>ALEX16<\/th>\n <th>anxiety<\/th>\n <th>artgluctot<\/th>\n <th>attachhome<\/th>\n <th>attachphone<\/th>\n <th>AvgHumidity<\/th>\n <th>avoidance<\/th>\n <th>cigs<\/th>\n <th>DIDF<\/th>\n <th>eatdrink<\/th>\n <th>ECR1<\/th>\n <th>ECR2<\/th>\n <th>ECR3<\/th>\n <th>ECR4<\/th>\n <th>ECR5<\/th>\n <th>ECR6<\/th>\n <th>ECR7<\/th>\n <th>ECR8<\/th>\n <th>ECR9<\/th>\n <th>ECR10<\/th>\n <th>ECR11<\/th>\n <th>ECR12<\/th>\n <th>ECR13<\/th>\n <th>ECR14<\/th>\n <th>ECR15<\/th>\n <th>ECR16<\/th>\n <th>ECR17<\/th>\n <th>ECR18<\/th>\n <th>ECR19<\/th>\n <th>ECR20<\/th>\n <th>ECR21<\/th>\n <th>ECR22<\/th>\n <th>ECR23<\/th>\n <th>ECR24<\/th>\n <th>ECR25<\/th>\n <th>ECR26<\/th>\n <th>ECR27<\/th>\n <th>ECR28<\/th>\n <th>ECR29<\/th>\n <th>ECR30<\/th>\n <th>ECR31<\/th>\n <th>ECR32<\/th>\n <th>ECR33<\/th>\n <th>ECR34<\/th>\n <th>ECR35<\/th>\n <th>ECR36<\/th>\n <th>endtime<\/th>\n <th>EOT<\/th>\n <th>exercise<\/th>\n <th>gluctot<\/th>\n <th>health<\/th>\n <th>HOME1<\/th>\n <th>HOME2<\/th>\n <th>HOME3<\/th>\n <th>HOME4<\/th>\n <th>HOME5<\/th>\n <th>HOME6<\/th>\n <th>HOME7<\/th>\n <th>HOME8<\/th>\n <th>HOME9<\/th>\n <th>KAMF1<\/th>\n <th>KAMF2<\/th>\n <th>KAMF3<\/th>\n <th>KAMF4<\/th>\n <th>KAMF5<\/th>\n <th>KAMF6<\/th>\n <th>KAMF7<\/th>\n <th>networksize<\/th>\n <th>nostalgia<\/th>\n <th>onlineid<\/th>\n <th>onlineid1<\/th>\n <th>onlineid2<\/th>\n <th>onlineid3<\/th>\n <th>onlineid4<\/th>\n <th>onlineid5<\/th>\n <th>onlineid6<\/th>\n <th>onlineid7<\/th>\n <th>onlineid8<\/th>\n <th>onlineid9<\/th>\n <th>onlineid10<\/th>\n <th>onlineide11<\/th>\n <th>phone1<\/th>\n <th>phone2<\/th>\n <th>phone3<\/th>\n <th>phone4<\/th>\n <th>phone5<\/th>\n <th>phone6<\/th>\n <th>phone7<\/th>\n <th>phone8<\/th>\n <th>phone9<\/th>\n <th>romantic<\/th>\n <th>scontrol1<\/th>\n <th>scontrol2<\/th>\n <th>scontrol3<\/th>\n <th>scontrol4<\/th>\n <th>scontrol5<\/th>\n <th>scontrol6<\/th>\n <th>scontrol7<\/th>\n <th>scontrol8<\/th>\n <th>scontrol9<\/th>\n <th>scontrol10<\/th>\n <th>scontrol11<\/th>\n <th>scontrol12<\/th>\n <th>scontrol13<\/th>\n <th>selfcontrol<\/th>\n <th>sex<\/th>\n <th>smoke<\/th>\n <th>SNI1<\/th>\n <th>SNI2<\/th>\n <th>SNI3<\/th>\n <th>SNI4<\/th>\n <th>SNI5<\/th>\n <th>SNI6<\/th>\n <th>SNI7<\/th>\n <th>SNI8<\/th>\n <th>SNI9<\/th>\n <th>SNI10<\/th>\n <th>SNI11<\/th>\n <th>SNI12<\/th>\n <th>SNI13<\/th>\n <th>SNI14<\/th>\n <th>SNI15<\/th>\n <th>SNI16<\/th>\n <th>SNI17<\/th>\n <th>SNI18<\/th>\n <th>SNI19<\/th>\n <th>SNI20<\/th>\n <th>SNI21<\/th>\n <th>SNI22<\/th>\n <th>SNI23<\/th>\n <th>SNI24<\/th>\n <th>SNI25<\/th>\n <th>SNI26<\/th>\n <th>SNI27<\/th>\n <th>SNI28<\/th>\n <th>SNI29<\/th>\n <th>SNI30<\/th>\n <th>SNI31<\/th>\n <th>SNI32<\/th>\n <th>SNS1<\/th>\n <th>SNS2<\/th>\n <th>SNS3<\/th>\n <th>SNS4<\/th>\n <th>SNS5<\/th>\n <th>SNS6<\/th>\n <th>SNS7<\/th>\n <th>socialdiversity<\/th>\n <th>socialembedded<\/th>\n <th>STRAQ_1<\/th>\n <th>STRAQ_2<\/th>\n <th>STRAQ_3<\/th>\n <th>STRAQ_4<\/th>\n <th>STRAQ_6<\/th>\n <th>STRAQ_7<\/th>\n <th>STRAQ_8<\/th>\n <th>STRAQ_9<\/th>\n <th>STRAQ_10<\/th>\n <th>STRAQ_11<\/th>\n <th>STRAQ_12<\/th>\n <th>STRAQ_19<\/th>\n <th>STRAQ_20<\/th>\n <th>STRAQ_21<\/th>\n <th>STRAQ_22<\/th>\n <th>STRAQ_23<\/th>\n <th>STRAQ_24<\/th>\n <th>STRAQ_25<\/th>\n <th>STRAQ_26<\/th>\n <th>STRAQ_27<\/th>\n <th>STRAQ_28<\/th>\n <th>STRAQ_29<\/th>\n <th>STRAQ_30<\/th>\n <th>STRAQ_31<\/th>\n <th>STRAQ_32<\/th>\n <th>STRAQ_33<\/th>\n <th>STRAQ_5<\/th>\n <th>STRAQ_13<\/th>\n <th>STRAQ_14<\/th>\n <th>STRAQ_15<\/th>\n <th>STRAQ_16<\/th>\n <th>STRAQ_17<\/th>\n <th>STRAQ_18<\/th>\n <th>STRAQ_34<\/th>\n <th>STRAQ_35<\/th>\n <th>STRAQ_36<\/th>\n <th>STRAQ_37<\/th>\n <th>STRAQ_38<\/th>\n <th>STRAQ_39<\/th>\n <th>STRAQ_40<\/th>\n <th>STRAQ_41<\/th>\n <th>STRAQ_42<\/th>\n <th>STRAQ_43<\/th>\n <th>STRAQ_44<\/th>\n <th>STRAQ_45<\/th>\n <th>STRAQ_46<\/th>\n <th>STRAQ_47<\/th>\n <th>STRAQ_48<\/th>\n <th>STRAQ_49<\/th>\n <th>STRAQ_50<\/th>\n <th>STRAQ_51<\/th>\n <th>STRAQ_52<\/th>\n <th>STRAQ_53<\/th>\n <th>STRAQ_54<\/th>\n <th>STRAQ_55<\/th>\n <th>STRAQ_56<\/th>\n <th>STRAQ_57<\/th>\n <th>stress<\/th>\n <th>stress1<\/th>\n <th>stress2<\/th>\n <th>stress3<\/th>\n <th>stress4<\/th>\n <th>stress5<\/th>\n <th>stress6<\/th>\n <th>stress7<\/th>\n <th>stress8<\/th>\n <th>stress9<\/th>\n <th>stress10<\/th>\n <th>stress11<\/th>\n <th>stress12<\/th>\n <th>stress13<\/th>\n <th>stress14<\/th>\n <th>Temperature_t1<\/th>\n <th>Temperature_t2<\/th>\n <th>thermotype<\/th>\n <th>avgtemp<\/th>\n <th>filter_.<\/th>\n <th>mintemp<\/th>\n <th>language<\/th>\n <th>langfamily<\/th>\n <th>Zanxiety<\/th>\n <th>Zavoidance<\/th>\n <th>Site<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"pageLength":3,"columnDefs":[{"className":"dt-right","targets":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"lengthMenu":[3,10,25,50,100]}},"evals":[],"jsHooks":[]}</script>
---
# 3.2 读取数据
## 对于常用的心理学数据文件,可用bruceR包读取csv文件
```r
# 函数的内嵌,记得要检查左右括号一一匹配,数量一致
penguin.Data <- bruceR::import(here::here('data',
'penguin',
'penguin_rawdata.csv'))
```
```
## <U+221A> Successfully imported: 1523 obs. of 247 variables
```
<div class="datatables html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-fcb0496b65d449dbec21" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-fcb0496b65d449dbec21">{"x":{"filter":"none","vertical":false,"fillContainer":true,"data":[["1","2","3","4","5","6","7","8","9","10"],[1975,1995,1995,1988,1991,1995,1996,1973,1996,1996],[1,2,4,2,2,2,1,3,2,3],[1,2,1,3,1,3,1,3,3,3],[1,2,1,4,1,1,1,2,1,1],[2,2,2,5,5,3,1,3,3,2],[2,2,4,3,2,2,4,4,2,4],[1,2,1,4,2,1,1,4,2,1],[2,2,4,2,3,1,2,4,2,2],[2,2,1,4,4,2,1,4,2,4],[4,4,1,4,1,1,4,4,2,4],[1,2,2,3,1,2,2,5,2,1],[1,2,1,2,2,1,1,3,1,4],[2,2,1,2,1,2,2,2,2,1],[4,2,2,4,2,3,4,2,2,2],[3,2,1,2,4,4,3,3,4,3],[4,3,1,4,4,5,5,4,3,5],[2,2,1,3,2,4,5,1,2,4],[3.72222222222222,4.05555555555556,1.44444444444444,4.72222222222222,2.11111111111111,2,2.55555555555556,3.05555555555556,3.55555555555556,4.38888888888889],[6,0,0,2,0,0,null,0,0,0],[3.11111111111111,4.88888888888889,1.33333333333333,3.88888888888889,4.66666666666667,3.33333333333333,3.11111111111111,3.55555555555556,3.33333333333333,3.22222222222222],[3.44444444444444,2,2,3,1.77777777777778,2.44444444444444,3.77777777777778,3.33333333333333,1.88888888888889,4.22222222222222],[89,89,89,89,89,89,89,89,89,89],[3.27777777777778,3,1.61111111111111,3.94444444444444,4.94444444444444,3.77777777777778,6.44444444444444,3.22222222222222,4,5.27777777777778],[15,null,null,null,null,null,null,10,null,1],[1.63636363636364,2.18181818181818,2,3.27272727272727,2.18181818181818,1.72727272727273,1.72727272727273,3.54545454545455,2,2.63636363636364],[1,1,1,2,1,1,1,1,1,1],[5,6,1,3,1,1,2,3,4,5],[5,4,1,6,1,1,1,2,4,6],[3,2,1,6,1,1,4,3,4,6],[5,5,1,5,1,2,1,2,4,5],[5,5,1,4,1,2,4,3,4,4],[3,2,1,4,5,1,1,3,1,3],[1,3,1,3,2,1,2,3,4,5],[6,5,1,3,1,2,7,3,4,7],[5,2,1,4,7,6,1,3,4,3],[2,3,1,4,1,2,4,1,4,3],[6,7,1,6,6,2,2,5,2,6],[3,4,1,5,1,2,1,2,4,4],[3,3,1,6,2,4,2,5,4,4],[2,3,7,5,1,1,1,4,1,2],[3,4,1,5,2,2,1,5,4,1],[3,5,3,5,1,1,2,3,4,4],[6,5,1,6,2,3,6,3,4,7],[1,5,1,5,2,2,4,2,4,4],[2,3,2,5,1,5,7,3,4,5],[2,4,2,5,7,5,1,2,4,7],[5,3,2,5,2,4,6,4,4,5],[3,2,2,4,5,4,7,3,4,5],[3,2,2,3,2,3,7,3,4,6],[2,3,1,4,4,4,7,3,4,5],[5,3,1,6,2,3,7,4,4,6],[5,4,1,3,6,3,7,4,4,7],[3,5,1,3,7,1,7,4,4,7],[2,3,1,4,6,3,6,3,4,4],[4,2,2,5,6,6,6,3,4,4],[2,2,2,3,6,5,7,2,4,5],[3,4,1,4,7,4,7,2,4,3],[3,2,2,5,2,3,7,3,4,6],[4,3,3,3,7,4,6,3,4,5],[5,3,1,2,6,5,7,4,4,6],[4,3,1,3,6,3,7,6,4,5],[2,3,2,4,7,3,7,2,4,4],["9:23:38","9:23:26","8:57:08","8:55:14","8:54:35","8:39:12","8:32:08","8:28:57","8:28:03","8:25:57"],[3,2.2,1.2,3,2.6,3.6,3.8,2.4,2.6,3],[2,2,2,2,2,2,2,2,2,2],[0,0,12,0,5,0,null,1,0,2],[4,4,4,3,4,4,4,1,3,3],[4,5,1,5,5,4,5,3,3,4],[3,5,1,4,5,4,2,3,3,5],[4,5,4,5,5,4,4,2,4,3],[3,5,1,5,5,4,5,4,5,3],[3,5,1,4,4,4,2,3,4,4],[2,4,1,2,5,2,1,4,3,2],[4,5,1,2,4,2,5,5,2,2],[3,5,1,4,4,3,1,4,3,3],[2,5,1,4,5,3,3,4,3,3],[4,1,5,5,1,3,2,3,3,4],[4,2,6,4,1,3,2,3,3,5],[5,6,5,3,3,3,2,2,2,1],[4,2,4,1,2,2,2,2,1,3],[4,3,3,2,2,2,2,2,3,2],[1,2,1,2,2,4,2,3,3,3],[2,2,1,2,1,4,2,3,1,2],[17,28,24,19,29,33,53,17,17,19],[4.33333333333333,6.5,6.83333333333333,3.5,1.5,2,5.83333333333333,6.33333333333333,5.66666666666667,5.16666666666667],[2.27272727272727,2.63636363636364,2.18181818181818,2,1.90909090909091,2.45454545454545,2.81818181818182,2.54545454545455,1.81818181818182,3.90909090909091],[2,3,3,1,3,4,4,2,2,5],[2,2,4,1,2,4,4,3,3,4],[2,3,2,2,1,2,2,3,2,5],[4,3,4,3,4,4,2,2,2,4],[2,3,1,2,1,3,3,3,2,3],[2,2,1,2,1,1,2,2,1,3],[2,2,1,2,1,2,2,4,2,4],[2,3,3,1,1,1,2,3,2,3],[3,3,3,2,2,2,4,2,1,3],[2,3,1,4,2,1,2,1,1,4],[2,2,1,2,3,3,4,3,2,5],[4,2,1,2,2,3,3,3,3,4],[4,2,4,4,1,3,4,4,2,4],[2,2,1,3,1,2,5,3,1,2],[5,2,4,2,1,3,4,3,4,4],[2,2,1,3,1,2,1,2,3,5],[2,2,1,2,3,2,3,4,1,4],[4,2,1,3,2,2,5,3,1,5],[4,2,1,4,1,3,5,4,1,5],[4,2,4,4,4,2,4,4,1,5],[2,2,1,1,2,2,2,2,2,2],[2,4,2,4,3,5,2,1,3,3],[2,4,3,2,5,5,4,4,3,4],[2,4,3,1,5,5,2,5,5,5],[1,4,2,1,3,2,2,2,5,1],[1,4,4,2,5,3,1,2,5,2],[4,3,2,1,5,4,3,3,3,1],[2,4,4,2,5,3,2,3,4,2],[2,2,1,3,4,3,2,2,5,4],[5,4,3,4,4,5,4,4,3,3],[4,3,5,3,3,5,5,3,4,2],[3,4,4,2,4,5,3,2,2,5],[5,5,4,2,4,4,1,3,4,3],[4,4,4,2,4,3,2,2,2,2],[2.84615384615385,3.76923076923077,3.15384615384615,2.23076923076923,4.15384615384615,4,2.53846153846154,2.76923076923077,3.69230769230769,2.84615384615385],[1,1,1,2,1,1,2,1,1,2],[1,2,2,2,2,2,2,1,2,1],[2,1,1,1,2,2,2,4,2,2],[1,1,1,1,1,1,1,1,1,1],[null,null,null,null,null,null,null,null,null,null],[4,4,4,4,2,4,4,4,4,4],[4,4,4,4,2,4,4,2,4,4],[5,1,4,5,5,5,5,5,5,5],[null,null,4,null,null,null,null,null,null,null],[1,8,2,1,8,2,3,8,2,6],[null,6,2,null,5,1,2,3,2,3],[6,4,5,5,7,5,8,4,3,8],[3,1,5,1,3,5,8,4,2,8],[1,1,1,1,2,1,1,1,1,1],[null,null,null,null,8,null,null,null,null,null],[1,2,2,1,1,2,2,2,2,2],[null,8,8,null,null,8,8,8,8,8],[3,3,2,3,3,1,1,1,1,1],[2,8,1,8,1,null,null,null,null,null],[6,5,6,4,8,null,null,null,null,null],[1,3,1,1,1,8,6,4,1,3],[1,1,1,1,1,1,1,2,1,1],[null,null,null,null,null,null,null,2,null,null],[1,1,1,2,1,2,2,2,2,1],["","","","","","Rowing Club","University Friends","ODAA","Oxford Latin Speaking Society",""],["","","","","","Rugby Club","Business Social","","Oxford Latin Conversation Society",""],["","","","","","","Lecturers/ Advisors","","Plato Reading Group",""],["","","","","","","Friends from home","","",""],["","","","","","","Neighbors","","",""],[null,null,null,null,null,7,20,1,2,null],[null,null,null,null,null,7,15,null,4,null],[null,null,null,null,null,null,5,null,1,null],[null,null,null,null,null,null,9,null,null,null],[null,null,null,null,null,null,6,null,null,null],[6,6,7,2,1,1,6,6,7,7],[5,7,7,5,2,2,7,6,7,4],[5,6,7,3,2,3,5,7,6,5],[3,7,7,4,1,2,5,6,6,5],[2,6,7,5,2,2,6,7,5,5],[5,7,6,2,1,2,6,6,3,5],[4,6,6,4,1,2,5,6,3,4],[5,7,8,5,7,6,null,7,6,6],[1,2,3,1,2,4,null,2,2,3],[4,2,4,4,1,2,2,3,3,1],[4,4,5,2,1,4,4,2,5,4],[4,3,4,3,1,4,2,3,4,4],[5,3,4,3,4,4,4,4,2,4],[2,3,4,4,4,4,5,2,2,3],[2,4,4,3,1,3,4,3,1,3],[2,5,4,3,3,4,5,4,2,2],[2,2,4,3,4,3,5,3,2,4],[4,5,5,2,1,2,4,2,4,5],[2,3,2,2,1,4,1,4,4,5],[2,2,1,2,1,2,2,2,2,1],[1,2,2,2,4,4,4,2,2,2],[4,4,4,3,4,2,2,3,2,1],[5,4,2,3,2,4,3,4,4,4],[4,4,2,3,3,1,2,4,5,3],[2,3,4,4,4,5,5,4,4,4],[2,3,5,4,4,3,2,4,2,2],[4,3,4,2,4,3,4,3,3,2],[3,3,5,2,4,4,4,4,3,3],[2,3,1,3,5,4,1,3,2,4],[4,3,4,2,4,4,5,4,3,5],[3,3,5,4,4,3,2,2,3,3],[2,3,1,3,4,3,2,3,4,3],[3,3,1,4,1,2,2,2,3,3],[4,3,5,3,1,2,5,1,4,4],[3,3,3,2,1,3,3,2,3,3],[4,3,1,4,4,4,2,4,1,1],[4,5,4,2,1,3,1,4,4,5],[3,5,4,4,1,2,1,3,5,5],[3,2,2,4,4,2,5,2,2,4],[2,4,2,5,1,2,1,3,2,4],[4,3,1,2,4,2,5,1,1,4],[4,3,2,2,3,3,1,4,3,4],[1,4,3,4,4,2,1,3,2,2],[2,4,2,3,5,4,2,5,1,4],[2,4,2,4,5,4,4,4,2,4],[4,4,4,3,4,4,2,4,2,4],[3,4,2,4,4,4,4,5,5,1],[4,2,2,3,4,4,5,2,2,4],[5,3,3,2,4,2,2,2,2,4],[4,3,2,3,3,3,2,1,2,4],[4,3,5,2,4,4,4,4,4,4],[1,4,2,3,4,2,2,3,2,3],[1,2,2,4,4,2,1,2,1,2],[4,3,2,3,1,2,1,4,4,2],[4,4,4,2,1,4,1,4,3,3],[3,3,4,3,4,2,4,3,3,4],[1,2,5,4,4,2,1,2,1,2],[2,3,5,4,4,2,1,2,1,2],[4,3,5,4,4,4,3,3,3,4],[4,4,2,5,1,3,5,2,4,5],[2,4,5,3,1,2,5,4,2,4],[2,4,4,3,4,2,1,3,2,2],[4,3,4,3,5,2,4,4,2,4],[2,4,2,2,4,3,3,2,2,4],[2,4,1,2,4,2,2,2,2,2],[1,2,5,4,1,1,4,2,2,2],[3.07692307692308,2.46153846153846,2.38461538461538,2.84615384615385,2.53846153846154,2.07692307692308,1.53846153846154,3,2.61538461538462,3.15384615384615],[4,2,3,3,3,2,1,4,5,3],[2,3,3,3,4,2,2,3,2,4],[4,3,4,4,3,3,1,3,3,5],[4,3,1,2,2,2,2,3,2,4],[4,2,2,3,2,2,2,3,2,3],[3,2,1,2,1,2,2,3,2,1],[4,2,2,3,3,2,1,4,2,3],[3,2,2,2,2,2,1,4,3,4],[3,2,3,3,2,2,2,1,2,3],[2,3,3,3,3,2,1,3,4,3],[4,2,3,4,3,2,2,2,1,2],[3,4,4,3,5,4,4,4,5,4],[2,4,2,3,2,2,2,3,3,2],[1,2,2,2,3,2,1,3,3,4],[34.9,35.8,34,36.9,35.3,34.7,36,36.5,34.7,35.9],[35.9,36,36.2,37,36.1,36.4,36.3,36.6,36.3,36.3],[2,2,2,2,4,4,2,2,2,2],[35.4,35.9,35.1,36.95,35.7,35.55,36.15,36.55,35.5,36.1],[1,1,1,1,1,1,1,1,1,1],[-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667,-1.66666666666667],[5,5,5,5,5,5,5,5,5,5],[1,1,1,1,1,1,1,1,1,1],[0.186319647739787,0.472682850177291,-1.77049556891649,1.0454092550523,-1.19776916404149,-1.29322356485399,-0.815951560791479,-0.386406757135223,0.0431380465210342,0.759046052614796],[-0.00190690952064737,-0.249805147204807,-1.48929633562561,0.593048860921336,1.48548251658431,0.44430991831084,2.82413300007877,-0.0514865570574791,0.642628508458168,1.7829604018053],["Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford","Oxford"]],"container":"<table class=\"display fill-container\">\n <thead>\n <tr>\n <th> <\/th>\n <th>age<\/th>\n <th>ALEX1<\/th>\n <th>ALEX2<\/th>\n <th>ALEX3<\/th>\n <th>ALEX4<\/th>\n <th>ALEX5<\/th>\n <th>ALEX6<\/th>\n <th>ALEX7<\/th>\n <th>ALEX8<\/th>\n <th>ALEX9<\/th>\n <th>ALEX10<\/th>\n <th>ALEX11<\/th>\n <th>ALEX12<\/th>\n <th>ALEX13<\/th>\n <th>ALEX14<\/th>\n <th>ALEX15<\/th>\n <th>ALEX16<\/th>\n <th>anxiety<\/th>\n <th>artgluctot<\/th>\n <th>attachhome<\/th>\n <th>attachphone<\/th>\n <th>AvgHumidity<\/th>\n <th>avoidance<\/th>\n <th>cigs<\/th>\n <th>DIDF<\/th>\n <th>eatdrink<\/th>\n <th>ECR1<\/th>\n <th>ECR2<\/th>\n <th>ECR3<\/th>\n <th>ECR4<\/th>\n <th>ECR5<\/th>\n <th>ECR6<\/th>\n <th>ECR7<\/th>\n <th>ECR8<\/th>\n <th>ECR9<\/th>\n <th>ECR10<\/th>\n <th>ECR11<\/th>\n <th>ECR12<\/th>\n <th>ECR13<\/th>\n <th>ECR14<\/th>\n <th>ECR15<\/th>\n <th>ECR16<\/th>\n <th>ECR17<\/th>\n <th>ECR18<\/th>\n <th>ECR19<\/th>\n <th>ECR20<\/th>\n <th>ECR21<\/th>\n <th>ECR22<\/th>\n <th>ECR23<\/th>\n <th>ECR24<\/th>\n <th>ECR25<\/th>\n <th>ECR26<\/th>\n <th>ECR27<\/th>\n <th>ECR28<\/th>\n <th>ECR29<\/th>\n <th>ECR30<\/th>\n <th>ECR31<\/th>\n <th>ECR32<\/th>\n <th>ECR33<\/th>\n <th>ECR34<\/th>\n <th>ECR35<\/th>\n <th>ECR36<\/th>\n <th>endtime<\/th>\n <th>EOT<\/th>\n <th>exercise<\/th>\n <th>gluctot<\/th>\n <th>health<\/th>\n <th>HOME1<\/th>\n <th>HOME2<\/th>\n <th>HOME3<\/th>\n <th>HOME4<\/th>\n <th>HOME5<\/th>\n <th>HOME6<\/th>\n <th>HOME7<\/th>\n <th>HOME8<\/th>\n <th>HOME9<\/th>\n <th>KAMF1<\/th>\n <th>KAMF2<\/th>\n <th>KAMF3<\/th>\n <th>KAMF4<\/th>\n <th>KAMF5<\/th>\n <th>KAMF6<\/th>\n <th>KAMF7<\/th>\n <th>networksize<\/th>\n <th>nostalgia<\/th>\n <th>onlineid<\/th>\n <th>onlineid1<\/th>\n <th>onlineid2<\/th>\n <th>onlineid3<\/th>\n <th>onlineid4<\/th>\n <th>onlineid5<\/th>\n <th>onlineid6<\/th>\n <th>onlineid7<\/th>\n <th>onlineid8<\/th>\n <th>onlineid9<\/th>\n <th>onlineid10<\/th>\n <th>onlineide11<\/th>\n <th>phone1<\/th>\n <th>phone2<\/th>\n <th>phone3<\/th>\n <th>phone4<\/th>\n <th>phone5<\/th>\n <th>phone6<\/th>\n <th>phone7<\/th>\n <th>phone8<\/th>\n <th>phone9<\/th>\n <th>romantic<\/th>\n <th>scontrol1<\/th>\n <th>scontrol2<\/th>\n <th>scontrol3<\/th>\n <th>scontrol4<\/th>\n <th>scontrol5<\/th>\n <th>scontrol6<\/th>\n <th>scontrol7<\/th>\n <th>scontrol8<\/th>\n <th>scontrol9<\/th>\n <th>scontrol10<\/th>\n <th>scontrol11<\/th>\n <th>scontrol12<\/th>\n <th>scontrol13<\/th>\n <th>selfcontrol<\/th>\n <th>sex<\/th>\n <th>smoke<\/th>\n <th>SNI1<\/th>\n <th>SNI2<\/th>\n <th>SNI3<\/th>\n <th>SNI4<\/th>\n <th>SNI5<\/th>\n <th>SNI6<\/th>\n <th>SNI7<\/th>\n <th>SNI8<\/th>\n <th>SNI9<\/th>\n <th>SNI10<\/th>\n <th>SNI11<\/th>\n <th>SNI12<\/th>\n <th>SNI13<\/th>\n <th>SNI14<\/th>\n <th>SNI15<\/th>\n <th>SNI16<\/th>\n <th>SNI17<\/th>\n <th>SNI18<\/th>\n <th>SNI19<\/th>\n <th>SNI20<\/th>\n <th>SNI21<\/th>\n <th>SNI22<\/th>\n <th>SNI23<\/th>\n <th>SNI24<\/th>\n <th>SNI25<\/th>\n <th>SNI26<\/th>\n <th>SNI27<\/th>\n <th>SNI28<\/th>\n <th>SNI29<\/th>\n <th>SNI30<\/th>\n <th>SNI31<\/th>\n <th>SNI32<\/th>\n <th>SNS1<\/th>\n <th>SNS2<\/th>\n <th>SNS3<\/th>\n <th>SNS4<\/th>\n <th>SNS5<\/th>\n <th>SNS6<\/th>\n <th>SNS7<\/th>\n <th>socialdiversity<\/th>\n <th>socialembedded<\/th>\n <th>STRAQ_1<\/th>\n <th>STRAQ_2<\/th>\n <th>STRAQ_3<\/th>\n <th>STRAQ_4<\/th>\n <th>STRAQ_6<\/th>\n <th>STRAQ_7<\/th>\n <th>STRAQ_8<\/th>\n <th>STRAQ_9<\/th>\n <th>STRAQ_10<\/th>\n <th>STRAQ_11<\/th>\n <th>STRAQ_12<\/th>\n <th>STRAQ_19<\/th>\n <th>STRAQ_20<\/th>\n <th>STRAQ_21<\/th>\n <th>STRAQ_22<\/th>\n <th>STRAQ_23<\/th>\n <th>STRAQ_24<\/th>\n <th>STRAQ_25<\/th>\n <th>STRAQ_26<\/th>\n <th>STRAQ_27<\/th>\n <th>STRAQ_28<\/th>\n <th>STRAQ_29<\/th>\n <th>STRAQ_30<\/th>\n <th>STRAQ_31<\/th>\n <th>STRAQ_32<\/th>\n <th>STRAQ_33<\/th>\n <th>STRAQ_5<\/th>\n <th>STRAQ_13<\/th>\n <th>STRAQ_14<\/th>\n <th>STRAQ_15<\/th>\n <th>STRAQ_16<\/th>\n <th>STRAQ_17<\/th>\n <th>STRAQ_18<\/th>\n <th>STRAQ_34<\/th>\n <th>STRAQ_35<\/th>\n <th>STRAQ_36<\/th>\n <th>STRAQ_37<\/th>\n <th>STRAQ_38<\/th>\n <th>STRAQ_39<\/th>\n <th>STRAQ_40<\/th>\n <th>STRAQ_41<\/th>\n <th>STRAQ_42<\/th>\n <th>STRAQ_43<\/th>\n <th>STRAQ_44<\/th>\n <th>STRAQ_45<\/th>\n <th>STRAQ_46<\/th>\n <th>STRAQ_47<\/th>\n <th>STRAQ_48<\/th>\n <th>STRAQ_49<\/th>\n <th>STRAQ_50<\/th>\n <th>STRAQ_51<\/th>\n <th>STRAQ_52<\/th>\n <th>STRAQ_53<\/th>\n <th>STRAQ_54<\/th>\n <th>STRAQ_55<\/th>\n <th>STRAQ_56<\/th>\n <th>STRAQ_57<\/th>\n <th>stress<\/th>\n <th>stress1<\/th>\n <th>stress2<\/th>\n <th>stress3<\/th>\n <th>stress4<\/th>\n <th>stress5<\/th>\n <th>stress6<\/th>\n <th>stress7<\/th>\n <th>stress8<\/th>\n <th>stress9<\/th>\n <th>stress10<\/th>\n <th>stress11<\/th>\n <th>stress12<\/th>\n <th>stress13<\/th>\n <th>stress14<\/th>\n <th>Temperature_t1<\/th>\n <th>Temperature_t2<\/th>\n <th>thermotype<\/th>\n <th>avgtemp<\/th>\n <th>filter_$<\/th>\n <th>mintemp<\/th>\n <th>language<\/th>\n <th>langfamily<\/th>\n <th>Zanxiety<\/th>\n <th>Zavoidance<\/th>\n <th>Site<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"pageLength":3,"columnDefs":[{"className":"dt-right","targets":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246]},{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"lengthMenu":[3,10,25,50,100]}},"evals":[],"jsHooks":[]}</script>
---
# 3.2 读取数据
## 读取txt文件
```r
# 读取.txt类型文件
match.data <- read.csv("./data/match/data_exp7_rep_categ_7302.out",
header = TRUE, sep = "\t",
stringsAsFactors = FALSE)
```
<font size=5.5>
- 'sep = "\t"': txt文件以“tab”作为分隔符时,参数为“\t”
- 'sep = ': 默认的分隔符为",",也有“;”,"","\n"等。
- 也可以使用read.table()函数读取
---
# 3.2 读取数据
## 读取txt文件
```r
# 读取.txt类型文件
match.data <- read.csv("./data/match/data_exp7_rep_categ_7302.out",
header = TRUE, sep = "\t",
stringsAsFactors = FALSE)
```
<div class="datatables html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-8d9f904d83aeaef6c733" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-8d9f904d83aeaef6c733">{"x":{"filter":"none","vertical":false,"fillContainer":true,"data":[["1","2","3","4","5","6","7","8","9","10"],["02-May-2018_14:36:40 7302 22 female R 1 1 1 self immoralOther J NA -1 1.0420 ","02-May-2018_14:36:42 7302 22 female R 1 1 2 self moralSelf H h 1 0.7564 ","02-May-2018_14:36:44 7302 22 female R 1 1 3 self immoralSelf H h 1 0.4825 ","02-May-2018_14:36:46 7302 22 female R 1 1 4 self moralSelf H h 1 0.5446 ","02-May-2018_14:36:47 7302 22 female R 1 1 5 self moralOther J j 1 0.5028 ","02-May-2018_14:36:49 7302 22 female R 1 1 6 self moralSelf H h 1 0.5228 ","02-May-2018_14:36:51 7302 22 female R 1 1 7 self immoralSelf H h 1 0.4969 ","02-May-2018_14:36:53 7302 22 female R 1 1 8 self moralOther J j 1 0.5110 ","02-May-2018_14:36:54 7302 22 female R 1 1 9 self immoralSelf H h 1 0.5591 ","02-May-2018_14:36:56 7302 22 female R 1 1 10 self immoralOther J j 1 0.7311 "]],"container":"<table class=\"display fill-container\">\n <thead>\n <tr>\n <th> <\/th>\n <th>Date.Sub.Age.Sex.Hand.Block.Bin.Trial.Task.Shape.corrResp.Resp.ACC.RT<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"pageLength":3,"columnDefs":[{"orderable":false,"targets":0}],"order":[],"autoWidth":false,"orderClasses":false,"lengthMenu":[3,10,25,50,100]}},"evals":[],"jsHooks":[]}</script>
---
# 3.3 认识R里的数据 (R语言中的对象)
- <font size=6> 经过以上的操作,我们的"Environment"里发生了什么变化?</font>
![show_env](./picture/chapter3/fig_3_1.png)
---
# 3.3 认识R里的数据 (R语言中的对象)
## 对象
<br>
<br>
<span style="font-size: 30px;"> partner × </span> <br>
<span style="font-size: 30px;"> object √ </span> <br>
- <span style="font-size: 30px;"> 在R中存储的数据称为对象,R语言数据处理实际上就是不断地创建和操控这些对象。 </span> <br>
---
# 3.3 认识R里的数据 (R语言中的对象)
## 查看对象
```r
class(first_path)
```
```
## [1] "character"
```
```r
class(match.data)
```
```
## [1] "data.frame"
```
```r
class(penguin.data)
```
```
## [1] "data.frame"
```
---
```r
str(first_path)
```
```
## chr "C:/Users/Pac.B/Desktop/test"
```
```r
str(penguin.data[, 1:5])
```
```
## 'data.frame': 1523 obs. of 5 variables:
## $ ď.żage: int 1975 1995 1995 1988 1991 1995 1996 1973 1996 1996 ...
## $ ALEX1 : int 1 2 4 2 2 2 1 3 2 3 ...
## $ ALEX2 : int 1 2 1 3 1 3 1 3 3 3 ...
## $ ALEX3 : int 1 2 1 4 1 1 1 2 1 1 ...
## $ ALEX4 : int 2 2 2 5 5 3 1 3 3 2 ...
```
---
```r
summary(penguin.data[, 1:5])
```
```
## ď.żage ALEX1 ALEX2 ALEX3
## Min. :1922 Min. :1.00 Min. :1.000 Min. :1.000
## 1st Qu.:1991 1st Qu.:2.00 1st Qu.:2.000 1st Qu.:1.000
## Median :1994 Median :2.00 Median :3.000 Median :2.000
## Mean :1991 Mean :2.51 Mean :2.756 Mean :2.027
## 3rd Qu.:1995 3rd Qu.:3.00 3rd Qu.:4.000 3rd Qu.:3.000
## Max. :1998 Max. :5.00 Max. :5.000 Max. :5.000
## NA's :39 NA's :15 NA's :15 NA's :15
## ALEX4
## Min. :1.000
## 1st Qu.:2.000
## Median :2.000
## Mean :2.654
## 3rd Qu.:3.000
## Max. :5.000
## NA's :15
```
```r
summary(first_path)
```
```
## Length Class Mode
## 1 character character
```
---
## 3.3 认识R里的数据 (R语言中的对象)
![data structure](https://devopedia.org/images/article/46/9213.1526125966.png)
<br>
<p align="right"><font size=2>from http://venus.ifca.unican.es/Rintro/dataStruct.html</font></p>
---
# 3.3 了解R里的数据 (R语言中的对象)
## R中的对象类型<br><br>
- <font size=6>Vector(向量)</font>
- <font size=6>Matrix(矩阵)</font>
- <font size=6>Array(数组)</font>
- <font size=6>Data frame(数据框)</font>
- <font size=6>List(列表)</font>
---
class: center, middle
<span style="font-size: 60px;">Any questions?</span> <br>
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create({
"highlightStyle": "github",
"highlightLines": true,
"countIncrementalSlides": false
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
// add `data-at-shortcutkeys` attribute to <body> to resolve conflicts with JAWS
// screen reader (see PR #262)
(function(d) {
let res = {};
d.querySelectorAll('.remark-help-content table tr').forEach(tr => {
const t = tr.querySelector('td:nth-child(2)').innerText;
tr.querySelectorAll('td:first-child .key').forEach(key => {
const k = key.innerText;
if (/^[a-z]$/.test(k)) res[k] = t; // must be a single letter (key)
});
});
d.body.setAttribute('data-at-shortcutkeys', JSON.stringify(res));
})(document);
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
text = code.textContent;
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$\$(.|\s)+\$\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
};
slideshow._releaseMath(document);
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>