Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Study #130

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open

Study #130

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
2244d37
Merge branch 'master' of github.com:DataScienceSpecialization/courses
rdpeng May 5, 2014
0f6ee1f
update
jtleek May 5, 2014
94ec143
Merge branch 'master' of github.com:DataScienceSpecialization/courses
rdpeng May 9, 2014
8ef31db
Merge branch 'master' of github.com:DataScienceSpecialization/courses
rdpeng May 21, 2014
72d6772
Merge branch 'master' of https://github.com/DataScienceSpecialization…
jtleek May 28, 2014
1125e7d
added pdfs for brian in statinf
jtleek May 28, 2014
f82089a
Merge branch 'master' of github.com:DataScienceSpecialization/courses
rdpeng Jun 2, 2014
361d657
Merge branch 'master' of github.com:DataScienceSpecialization/courses
rdpeng Jul 8, 2014
030b91e
Fix coding for dates
rdpeng Jul 22, 2014
44c42cc
Evaluate date/time code
rdpeng Jul 22, 2014
d32b869
updates/modifications to yhat example
rdpeng Jul 22, 2014
08d8ff0
Zip file of data used in lecture
rdpeng Jul 22, 2014
3e5be7e
Update PDF/PNG slides
rdpeng Jul 22, 2014
0c18204
Rename pdf slides
rdpeng Jul 22, 2014
7e2280d
Change Title fo article
leard Aug 3, 2014
a0d5e34
Change the expoent of Xip
leard Aug 4, 2014
f73712c
Merge pull request #55 from leard/master
ncarchedi Aug 11, 2014
7cf478a
Fix coding for dates
rdpeng Jul 22, 2014
b1e8d75
Evaluate date/time code
rdpeng Jul 22, 2014
729c43c
updates/modifications to yhat example
rdpeng Jul 22, 2014
9602b00
Zip file of data used in lecture
rdpeng Jul 22, 2014
7c04d49
Update PDF/PNG slides
rdpeng Jul 22, 2014
85848a3
Rename pdf slides
rdpeng Jul 22, 2014
62f24dd
Some new PDFs
rdpeng Sep 4, 2014
6d0df71
Merge remote-tracking branch 'github/master'
rdpeng Sep 4, 2014
f11fed6
Merge branch 'master' of github.com:rdpeng/courses
rdpeng Sep 4, 2014
8cc64c3
Merge pull request #64 from rdpeng/master
jtleek Sep 5, 2014
233d0a9
Merge branch 'master' of github.com:DataScienceSpecialization/courses
rdpeng Sep 18, 2014
5c9bbf9
Merge pull request #72 from rdpeng/master
rdpeng Oct 1, 2014
cbfdc36
Remove AP example with yhat key
rdpeng Oct 21, 2014
493a62f
Ignore AP_example.R with api key
rdpeng Oct 21, 2014
d4fc2e0
Update index.Rmd
azalea Oct 23, 2014
1301a45
Add dplyr material
rdpeng Dec 30, 2014
d8636c3
Update
rdpeng Dec 23, 2014
e28bce9
Update slides
rdpeng Dec 29, 2014
c6944be
Individual slides
rdpeng Dec 31, 2014
52d8682
Individual slides
rdpeng Dec 31, 2014
ebf9a71
Update index.Rmd
Roon Apr 26, 2015
dc55398
Update index.Rmd
Roon Apr 27, 2015
c07e213
Update index.Rmd
Roon May 9, 2015
0e59475
Update index.Rmd
Roon May 9, 2015
29a1b93
Update index.Rmd
Roon May 9, 2015
30f3232
Update index.Rmd
Roon May 9, 2015
eda89ca
Update index.Rmd
Roon May 9, 2015
af0571c
Update index.Rmd
Roon May 9, 2015
b69b02b
Update index.Rmd
Roon May 10, 2015
c865b64
Fix typo in kmeans clustering
rdpeng May 13, 2015
b8731c1
Merge pull request #75 from azalea/patch-1
rdpeng May 13, 2015
e9d093f
Merge pull request #105 from Roon/patch-9
rdpeng May 13, 2015
f834e9e
Merge pull request #104 from Roon/patch-8
rdpeng May 13, 2015
f40276e
Merge pull request #103 from Roon/patch-6
rdpeng May 13, 2015
b89b507
Merge pull request #102 from Roon/patch-5
rdpeng May 13, 2015
f33e10a
Merge pull request #100 from Roon/patch-3
rdpeng May 13, 2015
ef388d5
Merge pull request #99 from Roon/patch-2
rdpeng May 13, 2015
5dc6a65
Merge pull request #98 from Roon/patch-1
rdpeng May 13, 2015
64554c6
Merge pull request #97 from Roon/master
rdpeng May 13, 2015
122145b
Merge pull request #101 from Roon/patch-4
rdpeng May 13, 2015
a5ca31e
Merge commit '385e9a1f63928f0782c257ff2d08ec9b5a847f87'
rdpeng May 13, 2015
65c2f63
Merge commit 'eaed53d96e44a7c16145d1ac9701827607ff819e'
rdpeng May 13, 2015
d7ec731
Merge commit '33a0fc9'
rdpeng May 13, 2015
d1174f4
Merge commit 'fb57d5'
rdpeng May 13, 2015
f65be39
Fix complex coercion
rdpeng Jul 9, 2015
3ddf31b
Use librariesNew
rdpeng Jul 9, 2015
29b41bc
Update PDF
rdpeng Jul 9, 2015
3c7be37
Merge remote-tracking branch 'origin/master'
rdpeng Jul 9, 2015
52530b8
Chicago data
rdpeng Jul 13, 2015
73cfd12
Edited URL in 05_ReproducibleResearch/organizingADataAnalysis/index.Rmd
gdhorne Aug 6, 2015
11de7c7
Merge pull request #11 from gdhorne/master
rdpeng Aug 6, 2015
ce68321
Fix non-working qplot code
rdpeng Mar 16, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 02_RProgramming/ControlStructures/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
lib: ../../libraries
lib: ../../librariesNew
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
Expand Down Expand Up @@ -243,4 +243,4 @@ Summary

- Infinite loops should generally be avoided, even if they are theoretically correct.

- Control structures mentiond here are primarily useful for writing programs; for command-line interactive work, the *apply functions are more useful.
- Control structures mentiond here are primarily useful for writing programs; for command-line interactive work, the *apply functions are more useful.
223 changes: 151 additions & 72 deletions 02_RProgramming/ControlStructures/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@
<meta name="generator" content="slidify" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/default.css" media="all" >
<link rel="stylesheet" href="../../libraries/frameworks/io2012/phone.css"
<link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/default.css" media="all" >
<link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/phone.css"
media="only screen and (max-device-width: 480px)" >
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/slidify.css" >
<link rel="stylesheet" href="../../libraries/highlighters/highlight.js/css/tomorrow.css" />
<base target="_blank"> <!-- This amazingness opens all links in a new tab. -->
<script data-main="../../libraries/frameworks/io2012/js/slides"
src="../../libraries/frameworks/io2012/js/require-1.0.8.min.js">
<link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/slidify.css" >
<link rel="stylesheet" href="../../librariesNew/highlighters/highlight.js/css/tomorrow.css" />
<base target="_blank"> <!-- This amazingness opens all links in a new tab. -->

<!-- Grab CDN jQuery, fall back to local if offline -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
<script>window.jQuery || document.write('<script src="../../librariesNew/widgets/quiz/js/jquery.js"><\/script>')</script>
<script data-main="../../librariesNew/frameworks/io2012/js/slides"
src="../../librariesNew/frameworks/io2012/js/require-1.0.8.min.js">
</script>

<link rel="stylesheet" href = "../../assets/css/custom.css">
<link rel="stylesheet" href = "../../assets/css/ribbons.css">


</head>
<body style="opacity: 0">
<slides class="layout-widescreen">

<!-- LOGO SLIDE -->
<!-- END LOGO SLIDE -->
<slide class="title-slide segue nobackground">
<aside class="gdbar">
<img src="../../assets/img/bloomberg_shield.png">
</aside>
<hgroup class="auto-fadein">
<h1>Introduction to the R Language</h1>
<h2>Control Structures</h2>
<p>Roger Peng, Associate Professor<br/>Johns Hopkins Bloomberg School of Public Health</p>
</hgroup>
<article></article>
</slide>


<!-- TITLE SLIDE -->
<!-- Should I move this to a Local Layout File? -->
<slide class="title-slide segue nobackground">
<aside class="gdbar">
<img src="../../assets/img/bloomberg_shield.png">
</aside>
<hgroup class="auto-fadein">
<h1>Introduction to the R Language</h1>
<h2>Control Structures</h2>
<p>Roger Peng, Associate Professor<br/>Johns Hopkins Bloomberg School of Public Health</p>
</hgroup>
</slide>

<!-- SLIDES -->
<slide class="" id="slide-1" style="background:;">
<slide class="" id="slide-1" style="background:;">
<hgroup>
<h2>Control Structures</h2>
</hgroup>
<article>
<article data-timings="">
<p>Control structures in R allow you to control the flow of execution of the program, depending on runtime conditions. Common structures are</p>

<ul>
Expand All @@ -66,11 +66,11 @@ <h2>Control Structures</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-2" style="background:;">
<slide class="" id="slide-2" style="background:;">
<hgroup>
<h2>Control Structures: if</h2>
</hgroup>
<article>
<article data-timings="">
<pre><code class="r">if(&lt;condition&gt;) {
## do something
} else {
Expand All @@ -89,11 +89,11 @@ <h2>Control Structures: if</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-3" style="background:;">
<slide class="" id="slide-3" style="background:;">
<hgroup>
<h2>if</h2>
</hgroup>
<article>
<article data-timings="">
<p>This is a valid if/else structure.</p>

<pre><code class="r">if(x &gt; 3) {
Expand All @@ -116,11 +116,11 @@ <h2>if</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-4" style="background:;">
<slide class="" id="slide-4" style="background:;">
<hgroup>
<h2>if</h2>
</hgroup>
<article>
<article data-timings="">
<p>Of course, the else clause is not necessary. </p>

<pre><code class="r">if(&lt;condition1&gt;) {
Expand All @@ -136,11 +136,11 @@ <h2>if</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-5" style="background:;">
<slide class="" id="slide-5" style="background:;">
<hgroup>
<h2>for</h2>
</hgroup>
<article>
<article data-timings="">
<p><code>for</code> loops take an interator variable and assign it successive values from a sequence or vector. For loops are most commonly used for iterating over the elements of an object (list, vector, etc.)</p>

<pre><code class="r">for(i in 1:10) {
Expand All @@ -154,11 +154,11 @@ <h2>for</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-6" style="background:;">
<slide class="" id="slide-6" style="background:;">
<hgroup>
<h2>for</h2>
</hgroup>
<article>
<article data-timings="">
<p>These three loops have the same behavior.</p>

<pre><code class="r">x &lt;- c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;)
Expand All @@ -182,11 +182,11 @@ <h2>for</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-7" style="background:;">
<slide class="" id="slide-7" style="background:;">
<hgroup>
<h2>Nested for loops</h2>
</hgroup>
<article>
<article data-timings="">
<p><code>for</code> loops can be nested.</p>

<pre><code class="r">x &lt;- matrix(1:6, 2, 3)
Expand All @@ -204,11 +204,11 @@ <h2>Nested for loops</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-8" style="background:;">
<slide class="" id="slide-8" style="background:;">
<hgroup>
<h2>while</h2>
</hgroup>
<article>
<article data-timings="">
<p>While loops begin by testing a condition. If it is true, then they execute the loop body. Once the loop body is executed, the condition is tested again, and so forth.</p>

<pre><code class="r">count &lt;- 0
Expand All @@ -224,11 +224,11 @@ <h2>while</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-9" style="background:;">
<slide class="" id="slide-9" style="background:;">
<hgroup>
<h2>while</h2>
</hgroup>
<article>
<article data-timings="">
<p>Sometimes there will be more than one condition in the test.</p>

<pre><code class="r">z &lt;- 5
Expand All @@ -251,11 +251,11 @@ <h2>while</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-10" style="background:;">
<slide class="" id="slide-10" style="background:;">
<hgroup>
<h2>repeat</h2>
</hgroup>
<article>
<article data-timings="">
<p>Repeat initiates an infinite loop; these are not commonly used in statistical applications but they do have their uses. The only way to exit a <code>repeat</code> loop is to call <code>break</code>.</p>

<pre><code class="r">x0 &lt;- 1
Expand All @@ -276,22 +276,22 @@ <h2>repeat</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-11" style="background:;">
<slide class="" id="slide-11" style="background:;">
<hgroup>
<h2>repeat</h2>
</hgroup>
<article>
<article data-timings="">
<p>The loop in the previous slide is a bit dangerous because there’s no guarantee it will stop. Better to set a hard limit on the number of iterations (e.g. using a for loop) and then report whether convergence was achieved or not.</p>

</article>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-12" style="background:;">
<slide class="" id="slide-12" style="background:;">
<hgroup>
<h2>next, return</h2>
</hgroup>
<article>
<article data-timings="">
<p><code>next</code> is used to skip an iteration of a loop</p>

<pre><code class="r">for(i in 1:100) {
Expand All @@ -309,11 +309,11 @@ <h2>next, return</h2>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-13" style="background:;">
<slide class="" id="slide-13" style="background:;">
<hgroup>
<h2>Control Structures</h2>
</hgroup>
<article>
<article data-timings="">
<p>Summary</p>

<ul>
Expand All @@ -328,34 +328,113 @@ <h2>Control Structures</h2>

<slide class="backdrop"></slide>
</slides>

<!--[if IE]>
<div class="pagination pagination-small" id='io2012-ptoc' style="display:none;">
<ul>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=1 title='Control Structures'>
1
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=2 title='Control Structures: if'>
2
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=3 title='if'>
3
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=4 title='if'>
4
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=5 title='for'>
5
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=6 title='for'>
6
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=7 title='Nested for loops'>
7
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=8 title='while'>
8
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=9 title='while'>
9
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=10 title='repeat'>
10
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=11 title='repeat'>
11
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=12 title='next, return'>
12
</a>
</li>
<li>
<a href="#" target="_self" rel='tooltip'
data-slide=13 title='Control Structures'>
13
</a>
</li>
</ul>
</div> <!--[if IE]>
<script
src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js">
</script>
<script>CFInstall.check({mode: 'overlay'});</script>
<![endif]-->
</body>
<!-- Grab CDN jQuery, fall back to local if offline -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
<script>window.jQuery || document.write('<script src="../../libraries/widgets/quiz/js/jquery-1.7.min.js"><\/script>')</script>
<!-- Load Javascripts for Widgets -->
<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script> -->
<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>')
<!-- Load Javascripts for Widgets -->

<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script> -->
<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../librariesNew/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>')
</script>
<!-- LOAD HIGHLIGHTER JS FILES -->
<script src="../../libraries/highlighters/highlight.js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!-- DONE LOADING HIGHLIGHTER JS FILES -->
</html>
<script src="../../librariesNew/highlighters/highlight.js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!-- DONE LOADING HIGHLIGHTER JS FILES -->

</html>
Loading