-
Notifications
You must be signed in to change notification settings - Fork 1
/
R-Learning.html
121 lines (104 loc) · 5.21 KB
/
R-Learning.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
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="icon" type="image/png" href="./images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./images/favicon-16x16.png" sizes="16x16" />
<title>R Learning - SPK's Rationality Essays</title>
<link rel="stylesheet" type="text/css" href="./css/default.css" />
<link rel="stylesheet" type="text/css" href="./css/highlight.css" />
<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> -->
<!-- <script type="text/javascript" src="/js/header-links.js"></script> -->
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link href="atom.xml" type="application/atom+xml" rel="alternate" title="Sitewide ATOM/RSS Feed" />
<!-- Google Analytics stuff -->
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DEWF2J5BG8"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DEWF2J5BG8');
</script>
<script type="text/javascript" src="https://fast.fonts.net/jsapi/f7f47a40-b25b-44ee-9f9c-cfdfc8bb2741.js"></script>
</head>
<body>
<div id="header">
<div id="logo">
<a href="./">SPK's Rationality Essays</a>
</div>
<div id="navigation">
<a href="./">Home</a>
<a href="./notes.html">Notes</a>
<!-- <a href="/about.html">About</a> -->
<a href="./archive.html">Archive</a>
<a href="./atom.xml" type="application/atom+xml" rel="alternate" title="Sitewide ATOM/RSS Feed">RSS</a>
</div>
</div>
<div id="content">
<h1 id="post-title">R Learning</h1>
<!-- <center><img src="https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-prn1/t31.0-8/p600x600/10257116_10202295769100492_2438594605053717342_o.jpg" height="400" width="300" class="sujeet-pic" alt="Sujeet pic" /></center> -->
<h1 id="matrices">Matrices</h1>
<pre><code>matrix(data_vector, byrow = TRUE, nrow = 3)</code></pre>
<p>This fills the matrix with elements from <code>data_vector</code>.</p>
<pre><code>rownames(m) <- foo
colnames(m) <- bar</code></pre>
<p>This gives you neat row and column titles when you print the matrix.</p>
<p>Other stuff I learnt:</p>
<pre><code>matrix[,2] # select second column</code></pre>
<h1 id="factors">Factors</h1>
<p>nominal (like C++ enum) or ordinal (like movie ratings).</p>
<p>ordinal:</p>
<pre><code>factor(foo, ordered = TRUE, levels = c("bronze", "silver", "gold"))</code></pre>
<h1 id="data-frame">Data Frame</h1>
<p>data frame = table</p>
<pre><code>str(foo) gives you
number of observations (rows), number of variables (columns)
variable: type and first few observations
foo_frame[,"col_name"]
foo_frame$col_name
foo_frame[foo_frame$rings, "names"]
# The first part selects rows, the second part selects columns.
# Get column "bar"
foo_frame$bar</code></pre>
<h1 id="table">Table</h1>
<pre><code># To get count ratios
table(foo_frame$sex)
# To get column-wise ratios
table(foo_frame$sex, foo_frame$Survived)
# To get proportions
prop.table(table(foo_frame$sex, foo_frame$Survived), margin = 1)</code></pre>
<h1 id="workspace">Workspace</h1>
<p>contents:</p>
<pre><code>ls()</code></pre>
<h1 id="reference">Reference</h1>
<p><a href="https://www.datacamp.com/courses/free-introduction-to-r">Datacamp Introduction to R</a></p>
<div class="info">Created: May 9, 2016</div>
<div class="info">Last modified: September 28, 2019</div>
<div class="info">Status: in-progress notes</div>
<div class="info"><b>Tags</b>: notes, R</div>
<br />
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'spkrationalitytrainingground'; // required: replace example with your forum shortname
var disqus_identifier = '/R-Learning.html';
var disqus_title = 'R Learning';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<script type="text/javascript" src="https://fast.fonts.net/jsapi/f7f47a40-b25b-44ee-9f9c-cfdfc8bb2741.js"></script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
<div id="footer">
Site proudly generated by
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
</div>
</body>
</html>