-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.html
197 lines (197 loc) · 9.92 KB
/
reference.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>RNAseq Using R Programming with R</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-theme.css" />
<link rel="stylesheet" type="text/css" href="css/swc.css" />
<meta charset="UTF-8" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="lesson">
<div class="container card">
<div class="banner" align="right" style="margin-top: 5px">
<a href="http://monash.edu/bioinformatics" title="Monash Bioinformatics Platform">
<div style="margin-right: 5px;" class="label swc-blue-bg">Monash Bioinformatics Platform</div>
</a>
</div>
<article>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<a href="index.html"><h1 class="title">Programming with R</h1></a>
<h2 class="subtitle">Reference</h2>
<h2 id="basic-operation">Basic Operation</h2>
<ul>
<li><code># this is a comment in R</code></li>
<li>Use <code>x <- 3</code> to assign a value, <code>3</code>, to a variable, <code>x</code></li>
<li>R counts from 1, unlike many other programming languages (e.g., Python)</li>
<li><code>length(thing)</code> returns the number of elements contained in the variable <code>collection</code></li>
<li><code>c(value1, value2, value3)</code> creates a vector</li>
<li><code>container[i]</code> selects the i’th element from the variable <code>container</code></li>
</ul>
<p>List objects in current environment <code>ls()</code></p>
<p>Remove objects in current environment <code>rm(x)</code></p>
<p>Remove all objects from current environment <code>rm(list = ls())</code></p>
<h2 id="control-flow">Control Flow</h2>
<ul>
<li><p>Create a contitional using <code>if</code>, <code>else if</code>, and <code>else</code></p>
<pre><code>if(x > 0){
print("value is positive")
} else if (x < 0){
print("value is negative")
} else{
print("value is neither positive nor negative")
}</code></pre></li>
<li><p>create a <code>for</code> loop to process elements in a collection one at a time</p>
<pre><code>for (i in 1:5) {
print(i)
}</code></pre></li>
</ul>
<p>This will print:</p>
<pre><code> 1
2
3
4
5</code></pre>
<ul>
<li>Use <code>==</code> to test for equality</li>
<li><code>3 == 3</code>, will return <code>TRUE</code>,</li>
<li><code>'apple' == 'orange'</code> will return <code>FALSE</code></li>
<li><code>X & Y</code> is <code>TRUE</code> is both X and Y are true</li>
<li><code>X | Y</code> is <code>TRUE</code> if either X or Y, or both are true</li>
</ul>
<h2 id="functions">Functions</h2>
<ul>
<li><p>Defining a function:</p>
<pre><code>is_positive <- function(integer_value){
if(integer_value > 0){
TRUE
}
else{
FALSE
{
}</code></pre></li>
</ul>
<p>In R, the last executed line of a function is automatically returned</p>
<ul>
<li><p>Specifying a default value for a function argument</p>
<pre><code>increment_me <- function(value_to_increment, value_to_increment_by = 1){
value_to_increment + value_to_increment_by
}</code></pre></li>
</ul>
<p><code>increment_me(4)</code>, will return 5</p>
<p><code>increment_me(4, 6)</code>, will return 10</p>
<ul>
<li><p>Call a function by using <code>function_name(function_arguments)</code></p>
<ul>
<li><p>apply family of functions:</p>
<pre><code>apply()
sapply()
lapply()
mapply()</code></pre></li>
</ul></li>
</ul>
<p><code>apply(dat, MARGIN = 2, mean)</code> will return the average (<code>mean</code>) of each column in <code>dat</code></p>
<h2 id="packages">Packages</h2>
<ul>
<li>Install package by using <code>install.packages("package-name")</code></li>
<li>Update packages by using <code>update.packages("package-name")</code></li>
<li>Load packages by using <code>library("package-name")</code></li>
</ul>
<h2 id="glossary">Glossary</h2>
<dl>
<dt><span id="argument">argument</span></dt>
<dd><p>A value given to a function or program when it runs. The term is often used interchangeably (and inconsistently) with <a href="#parameter">parameter</a>.</p>
</dd>
<dt><span id="call-stack">call stack</span></dt>
<dd><p>A data structure inside a running program that keeps track of active function calls. Each call’s variables are stored in a <a href="#stack-frame">stack frame</a>; a new stack frame is put on top of the stack for each call, and discarded when the call is finished.</p>
</dd>
<dt><span id="comma-separated-values-(csv)">comma-separated values (CSV)</span></dt>
<dd><p>A common textual representation for tables in which the values in each row are separated by commas.</p>
</dd>
<dt><span id="comment">comment</span></dt>
<dd><p>A remark in a program that is intended to help human readers understand what is going on, but is ignored by the computer. Comments in Python, R, and the Unix shell start with a <code>#</code> character and run to the end of the line; comments in SQL start with <code>--</code>, and other languages have other conventions.</p>
</dd>
<dt><span id="conditional-statement">conditional statement</span></dt>
<dd><p>A statement in a program that might or might not be executed depending on whether a test is true or false.</p>
</dd>
<dt><span id="documentation">documentation</span></dt>
<dd><p>Human-language text written to explain what software does, how it works, or how to use it.</p>
</dd>
<dt><span id="encapsulation">encapsulation</span></dt>
<dd><p>The practice of hiding something’s implementation details so that the rest of a program can worry about <em>what</em> it does rather than <em>how</em> it does it.</p>
</dd>
<dt><span id="for-loop">for loop</span></dt>
<dd><p>A loop that is executed once for each value in some kind of set, list, or range. See also: <a href="#while-loop">while loop</a>.</p>
</dd>
<dt><span id="function-body">function body</span></dt>
<dd><p>The statements that are executed inside a function.</p>
</dd>
<dt><span id="function-call">function call</span></dt>
<dd><p>A use of a function in another piece of software.</p>
</dd>
<dt><span id="function-composition">function composition</span></dt>
<dd><p>The immediate application of one function to the result of another, such as <code>f(g(x))</code>.</p>
</dd>
<dt><span id="index">index</span></dt>
<dd><p>A subscript that specifies the location of a single value in a collection, such as a single pixel in an image.</p>
</dd>
<dt><span id="loop-variable">loop variable</span></dt>
<dd><p>The variable that keeps track of the progress of the loop.</p>
</dd>
<dt><span id="notional-machine">notional machine</span></dt>
<dd><p>An abstraction of a computer used to think about what it can and will do.</p>
</dd>
<dt><span id="parameter">parameter</span></dt>
<dd><p>A variable named in the function’s declaration that is used to hold a value passed into the call. The term is often used interchangeably (and inconsistently) with <a href="#argument">argument</a>.</p>
</dd>
<dt><span id="pipe">pipe</span></dt>
<dd><p>A connection from the output of one program to the input of another. When two or more programs are connected in this way, they are called a “pipeline”.</p>
</dd>
<dt><span id="return-statement">return statement</span></dt>
<dd><p>A statement that causes a function to stop executing and return a value to its caller immediately.</p>
</dd>
<dt><span id="shape-(of-an-array)">shape (of an array)</span></dt>
<dd><p>An array’s dimensions, represented as a vector. For example, a 5×3 array’s shape is <code>(5,3)</code>.</p>
</dd>
<dt><span id="silent-failure">silent failure</span></dt>
<dd><p>Failing without producing any warning messages. Silent failures are hard to detect and debug.</p>
</dd>
<dt><span id="slice">slice</span></dt>
<dd><p>A regular subsequence of a larger sequence, such as the first five elements or every second element.</p>
</dd>
<dt><span id="stack-frame">stack frame</span></dt>
<dd><p>A data structure that provides storage for a function’s local variables. Each time a function is called, a new stack frame is created and put on the top of the <a href="#call-stack">call stack</a>. When the function returns, the stack frame is discarded.</p>
</dd>
<dt><span id="standard-input-(stdin)">standard input (stdin)</span></dt>
<dd><p>A process’s default input stream. In interactive command-line applications, it is typically connected to the keyboard; in a <a href="#pipe">pipe</a>, it receives data from the <a href="#standard-output">standard output</a> of the preceding process.</p>
</dd>
<dt><span id="standard-output-(stdout)">standard output (stdout)</span></dt>
<dd><p>A process’s default output stream. In interactive command-line applications, data sent to standard output is displayed on the screen; in a <a href="#pipe">pipe</a>, it is passed to the <a href="#standard-input">standard input</a> of the next process.</p>
</dd>
<dt><span id="string">string</span></dt>
<dd><p>Short for “character string”, a <a href="#sequence">sequence</a> of zero or more characters.</p>
</dd>
<dt><span id="while-loop">while loop</span></dt>
<dd><p>A loop that keeps executing as long as some condition is true. See also: <a href="#for-loop">for loop</a>.</p>
</dd>
</dl>
</div>
</div>
</article>
<div class="footer">
<a class="label swc-blue-bg" href="https://github.com/MonashBioinformaticsPlatform/RNAseq-DE-analysis-with-R">Source</a>
</div>
</div>
<!-- Javascript placed at the end of the document so the pages load faster -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="css/bootstrap/bootstrap-js/bootstrap.js"></script>
</body>
</html>