-
Notifications
You must be signed in to change notification settings - Fork 0
/
098-FunctionList.Rmd
139 lines (127 loc) · 31.6 KB
/
098-FunctionList.Rmd
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
# Function list
## Week 1
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| Function | Explanation | Section |
+:=====================+:=======================================================================================================================================================+:======================+
| `install.packages()` | Installs a package. Typically used once to install new packages. | \@ref(install-lib) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `library()` | Loads an installed package. Packages should be loaded with every new R session and inside your RMarkdown documents to ensure proper knitting. | \@ref(install-lib) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `+, -, *, /, ^` | Basic operators used for arithmetic in R. The order of operations is BEDMAS. | \@ref(basicoperators) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `sqrt()` | Computes the square root of a number. | \@ref(usingfunctions) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `abs()` | Calculates the absolute value of a number. | \@ref(usingfunctions) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `round()` | Round a number to a specified amount of digits. | \@ref(multiarg) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `log()` | Computes the (natural) logarithm of a number. | \@ref(functex) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `rep()` | Replicates elements (numbers, vectors, lists) a specified amount of times. | \@ref(functex) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `print()` | Print the value of a variable to the console. | \@ref(usecomments) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `seq()` | Generate a sequence of numbers from a starting value to an end value by a set increment. | \@ref(variablesex) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
| `#` | Indicates the start of a comment in R code. Everything after \# is ignored by R. Comments enable you to document your R code with human readable text. | \@ref(usecomments) |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
## Week 2
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| Function | Explanation | Section |
+:==================+:=========================================================================================================================================================================================================================================================+:============================================+
| | **General functions** | |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `read_csv()` | Load a .csv file into R as a data frame. | \@ref(loadingdata) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `head()` | Print the first 6 rows of a data frame to the console. | \@ref(firstlook) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `tail()` | Print the last 6 rows of a data frame to the console. | \@ref(firstlook) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `glimpse()` | Print a brief summary of a data frame to the console. | \@ref(firstlook) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `length()` | Calculate the length of a vector. | \@ref(wranglefirst) and \@ref(returnlength) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `sum()` | Calculate the sum of all values in a vector. | \@ref(returnsum) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `c()` | Create a vector (combine elements). A vector is a variable that holds multiple elements. | \@ref(multiplot) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `data.frame()` | Create a data frame from variables. | \@ref(descbycond) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| | **Data wrangling** | |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `$` | Extract a single column/variable from a data frame. | \@ref(firstlook) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `%>%` | The pipe operator allows you to chain multiple operations on a data frame (without saving intermediates). The pipe operator can be read as "and then". | \@ref(wranglefirst) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `filter()` | Keep only those rows of a data frame that satisfy a certain condition, usually based on values in a specific column. | \@ref(onecountry) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `group_by()` | Divide a data frame into groups based on the values in a given column. If given two column names, groups based on the first column are divided into subgroups based on the second column. Operations on grouped data frames are performed by (sub)group. | \@ref(wranglefirst) and \@ref(groupsumknit) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `summarise()` | Create a data frame with summary statistics. Combine with `group_by()` to calculate summary statistics for groups and subgroups. | \@ref(wranglefirst) and \@ref(groupsumknit) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `%in%` | Match values in a vector. Can be used to filter a data frame for multiple values. | \@ref(multiplot) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| | **Visualization** | |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `ggplot()` | Create a plot of the data in a data frame. You can create various kinds of plots with a wide range of aesthetics based on the specification of `ggplot` layers. Layers are added by using the `+` operator. | \@ref(plotcounts) and \@ref(addggplot) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `knittr::kable()` | Apply to a data frame to print out a nice looking table in your knitted document. | \@ref(groupsumknit) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| | **Descriptive statistics** | |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `mean()` | Calculate the mean of a vector. | \@ref(returnmean) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `median()` | Calculate the median of a vector. | \@ref(returnmedian) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `range()` | Calculate the minimum and maximum values of a vector. | \@ref(returnrange) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `var()` | Calculate the variance of a vector. Variance is the sum of squares divided by $n-1$. | \@ref(returnvar) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| `sd()` | Calculate the standard deviation of a vector. This is equal to `sqrt(var)`. | \@ref(returnsd) |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
## Week 3
+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+
| Function | Explanation | Section |
+:===============+:=======================================================================================================================================================================================================================================================================================+:=====================+
| `cor()` | Calculate the correlation between 2 vectors. | \@ref(corforcor) |
+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+
| `annotate()` | ggplot layer to annotate a plot with text and/or symbols | \@ref(scatterannote) |
+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+
| `rnorm()` | Generate a vector of random numbers drawn from a normal distribution. Part of the \*norm family of functions for the normal distribution. See [the textbook](https://thomashulst.github.io/quantrma/chance.html#prob-dist) for an explanation of the different distribution functions. | \@ref(lotsofscatter) |
+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+
| `facet_wrap()` | Divide your plot into multiple facets based on a condition/variable. | \@ref(lotsofscatter) |
+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+
| `select()` | Reduce a data frame to only the given columns | \@ref(exampleq1) |
+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+
## Week 4
+----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+
| Function | Explanation | Section |
+:=====================+:============================================================================================================================================================================================================================================================================================+:==================+
| `for (i in x:y) { }` | Programmatically loop over the code between `{ }` (i.e. evaluate the code multiple times) from a start index (`x`) to end index (`y`). | \@ref(chanceex) |
+----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+
| `sample()` | Take a random sample of the elements in a vector. | \@ref(samplefunc) |
+----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+
| `rbinom()` | Generate a vector of random numbers drawn from a binomial distribution. Part of the \*binom family of functions for the binomial distribution. See [the textbook](https://thomashulst.github.io/quantrma/chance.html#prob-dist) for an explanation of the different distribution functions. | \@ref(rbinom) |
+----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+
| `set.seed()` | Set the state of the random number generator in R. Typically used to get the same random sampling between R sessions. | \@ref(normex) |
+----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+
## Week 5
+------------------+---------------------------------------------------------------------------------------------------------------+-------------------+
| Function | Explanation | Section |
+:=================+:==============================================================================================================+:==================+
| `replicate()` | Evaluate an expression multiple times. Analogous to `rep()` but for functions/expressions instead of vectors. | \@ref(q7rep) |
+------------------+---------------------------------------------------------------------------------------------------------------+-------------------+
| `pivot_longer()` | Pivot data from wide format to long format. Tidyverse functions (like `ggplot`) expect long format data. | \@ref(stroopdata) |
+------------------+---------------------------------------------------------------------------------------------------------------+-------------------+
| `pivot_wider()` | Pivot data from long format to wide format. | \@ref(stroopdata) |
+------------------+---------------------------------------------------------------------------------------------------------------+-------------------+
| `mutate()` | Create a new variable from an existing one. | \@ref(stroopdata) |
+------------------+---------------------------------------------------------------------------------------------------------------+-------------------+
| `n()` | Calculate the number of observations in a group. | \@ref(stroopdata) |
+------------------+---------------------------------------------------------------------------------------------------------------+-------------------+
## Week 6
+------------+---------------------------------------------------------+---------------+
| Function | Explanation | Section |
+:===========+:========================================================+:==============+
| `t.test()` | Performs one and two sample t-tests on vectors of data. | \@ref(ttestR) |
+------------+---------------------------------------------------------+---------------+