全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
867 0
2017-03-30



1490843877(1).jpg
Contents
1 Introduction 1
1.1 Who should read this book . . . . . . . . . . . . . . . . 3
1.2 What you will get out of this book . . . . . . . . . . . . 3
1.3 Meta-techniques . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Recommended reading . . . . . . . . . . . . . . . . . . 5
1.5 Getting help . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 Acknowledgments . . . . . . . . . . . . . . . . . . . . . 6
1.7 Conventions . . . . . . . . . . . . . . . . . . . . . . . . 8
1.8 Colophon . . . . . . . . . . . . . . . . . . . . . . . . . . 8
I Foundations 11
2 Data structures 13
2.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.1 Atomic vectors . . . . . . . . . . . . . . . . . . . 15
2.1.1.1 Types and tests . . . . . . . . . . . . . 16
2.1.1.2 Coercion . . . . . . . . . . . . . . . . . 16
2.1.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.3 Exercises . . . . . . . . . . . . . . . . . . . . . . 19
2.2 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2.0.1 Names . . . . . . . . . . . . . . . . . . 20
2.2.1 Factors . . . . . . . . . . . . . . . . . . . . . . . 21
2.2.2 Exercises . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Matrices and arrays . . . . . . . . . . . . . . . . . . . . 24
ix
x Contents
2.3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . 26
2.4 Data frames . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.1 Creation . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.2 Testing and coercion . . . . . . . . . . . . . . . . 28
2.4.3 Combining data frames . . . . . . . . . . . . . . 28
2.4.4 Special columns . . . . . . . . . . . . . . . . . . . 29
2.4.5 Exercises . . . . . . . . . . . . . . . . . . . . . . 30
2.5 Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3 Subsetting 33
3.1 Data types . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.1.1 Atomic vectors . . . . . . . . . . . . . . . . . . . 34
3.1.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.1.3 Matrices and arrays . . . . . . . . . . . . . . . . 37
3.1.4 Data frames . . . . . . . . . . . . . . . . . . . . . 38
3.1.5 S3 objects . . . . . . . . . . . . . . . . . . . . . . 39
3.1.6 S4 objects . . . . . . . . . . . . . . . . . . . . . . 39
3.1.7 Exercises . . . . . . . . . . . . . . . . . . . . . . 39
3.2 Subsetting operators . . . . . . . . . . . . . . . . . . . . 40
3.2.1 Simplifying vs. preserving subsetting . . . . . . . 41
3.2.2 $ . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.2.3 Missing/out of bounds indices . . . . . . . . . . . 44
3.2.4 Exercises . . . . . . . . . . . . . . . . . . . . . . 45
3.3 Subsetting and assignment . . . . . . . . . . . . . . . . 45
3.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . 46
3.4.1 Lookup tables (character subsetting) . . . . . . . 46
3.4.2 Matching and merging by hand (integer subset-
ting) . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.4.3 Random samples/bootstrap (integer subsetting) 48
3.4.4 Ordering (integer subsetting) . . . . . . . . . . . 49
Contents xi
3.4.5 Expanding aggregated counts (integer subsetting) 50
3.4.6 Removing columns from data frames (character
subsetting) . . . . . . . . . . . . . . . . . . . . . 51
3.4.7 Selecting rows based on a condition (logical sub-
setting) . . . . . . . . . . . . . . . . . . . . . . . 51
3.4.8 Boolean algebra vs. sets (logical & integer subset-
ting) . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.4.9 Exercises . . . . . . . . . . . . . . . . . . . . . . 54
3.5 Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4 Vocabulary 57
4.1 The basics . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.2 Common data structures . . . . . . . . . . . . . . . . . 59
4.3 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.4 Working with R . . . . . . . . . . . . . . . . . . . . . . 61
4.5 I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5 Style guide 63
5.1 Notation and naming . . . . . . . . . . . . . . . . . . . 63
5.1.1 File names . . . . . . . . . . . . . . . . . . . . . 63
5.1.2 Object names . . . . . . . . . . . . . . . . . . . . 64
5.2 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.2.1 Spacing . . . . . . . . . . . . . . . . . . . . . . . 65
5.2.2 Curly braces . . . . . . . . . . . . . . . . . . . . 66
5.2.3 Line length . . . . . . . . . . . . . . . . . . . . . 67
5.2.4 Indentation . . . . . . . . . . . . . . . . . . . . . 67
5.2.5 Assignment . . . . . . . . . . . . . . . . . . . . . 67
5.3 Organisation . . . . . . . . . . . . . . . . . . . . . . . . 68
5.3.1 Commenting guidelines . . . . . . . . . . . . . . 68
xii Contents
6 Functions 69
6.1 Function components . . . . . . . . . . . . . . . . . . . 71
6.1.1 Primitive functions . . . . . . . . . . . . . . . . . 71
6.1.2 Exercises . . . . . . . . . . . . . . . . . . . . . . 72
6.2 Lexical scoping . . . . . . . . . . . . . . . . . . . . . . . 73
6.2.1 Name masking . . . . . . . . . . . . . . . . . . . 74
6.2.2 Functions vs. variables . . . . . . . . . . . . . . . 75
6.2.3 A fresh start . . . . . . . . . . . . . . . . . . . . 76
6.2.4 Dynamic lookup . . . . . . . . . . . . . . . . . . 77
6.2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . 78
6.3 Every operation is a function call . . . . . . . . . . . . 79
6.4 Function arguments . . . . . . . . . . . . . . . . . . . . 81
6.4.1 Calling functions . . . . . . . . . . . . . . . . . . 81
6.4.2 Calling a function given a list of arguments . . . 83
6.4.3 Default and missing arguments . . . . . . . . . . 83
6.4.4 Lazy evaluation . . . . . . . . . . . . . . . . . . . 84
6.4.5 ... . . . . . . . . . . . . . . . . . . . . . . . . . . 88
6.4.6 Exercises . . . . . . . . . . . . . . . . . . . . . . 89
6.5 Special calls . . . . . . . . . . . . . . . . . . . . . . . . 89
6.5.1 Infix functions . . . . . . . . . . . . . . . . . . . 90
6.5.2 Replacement functions . . . . . . . . . . . . . . . 91
6.5.3 Exercises . . . . . . . . . . . . . . . . . . . . . . 93
6.6 Return values . . . . . . . . . . . . . . . . . . . . . . . 94
6.6.1 On exit . . . . . . . . . . . . . . . . . . . . . . . 97
6.6.2 Exercises . . . . . . . . . . . . . . . . . . . . . . 97
6.7 Quiz answers . . . . . . . . . . . . . . . . . . . . . . . . 98


Index
Advanced R-Chapman and Hall_CRC (2014).pdf
大小:(3.42 MB)

只需: 10 个论坛币  马上下载



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群