r introduction - daviddalpiaz.github.io · r introduction author: david dalpiaz created date:...
TRANSCRIPT
![Page 1: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/1.jpg)
R Introduction
David DalpiazSTAT 430, Fall 2017
1
![Page 2: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/2.jpg)
What the heck is R?
• R is a programming language designed specifically for statisticalcomputing and graphics.
• R is an interactive interface to many different tools.• R is based on the S language, which was developed by Bell
laboratories.• R is free, specifically open source.
• “Think free as in free speech, not free beer.”• R and RStudio are actually both.
• R is cool.
2
![Page 3: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/3.jpg)
Learning is HARD!
3
![Page 4: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/4.jpg)
Help?
The only way to learn R (or anything), is to fail. Then, get help.
• ?name_of_thing• Google!!!• Stack Overflow• R Resources• Ask!
4
![Page 5: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/5.jpg)
RStudio
5
![Page 6: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/6.jpg)
Know thine RStudio Environment
There are a lot of keyboard shortcuts in RStudio. These shortcutsare meant to speed up your work.
To view all the options, you must engage the keyboard shortcut thatrules them all:
• Windows: Alt + Shift + K• macOS: Option + Shift + K
6
![Page 7: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/7.jpg)
Some Favorites
1. Autocomplete command• Both: Tab
2. Runs the current line or selection from the editor to the consoleand runs it
• Windows: Ctrl + Enter• macOS: Cmd + Enter
3. Comment multiple lines.• Windows: Ctrl + Shift + C• macOS: Command + Shift + C
4. “Reformat”" Code:• Windows: Ctrl + Shift + A• macOS: Command + Shift + A
More to come when we introduce rmarkdown. . .7
![Page 8: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/8.jpg)
Objects and Functions
To understand computations in R, two slogans are helpful:Everything that exists is an object. Everything thathappens is a function call. — John Chambers
And when we say everything, we mean everything. Even a functionis an object.
8
![Page 9: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/9.jpg)
Assignment
<- or = ?That is the question.
9
![Page 10: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/10.jpg)
Attach
attach(dataset)
Do not ever do this.You might curse me now, but you’ll thank me later.
10
![Page 11: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/11.jpg)
Vectors
• There is no scalar.• Be aware of vectorization!
11
![Page 12: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/12.jpg)
Packages
Use them!They are what makes R great.
12
![Page 13: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/13.jpg)
Style
Have one!
• Spaces around binary operators!• Indent two spaces!• Pick an assignment operator and stick to it.• Get some inspiration from Hadley or Google.
Be consistent!
• With yourself!• With your group!• With your company!
13
![Page 14: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/14.jpg)
Next Time
• Lists?• Importing Data?• Frames vs Tibbles?• rmarkdown!
14
![Page 15: R Introduction - daviddalpiaz.github.io · R Introduction Author: David Dalpiaz Created Date: 8/30/2017 10:01:45 AM](https://reader033.vdocuments.net/reader033/viewer/2022051904/5ff54758e82d6614354a0739/html5/thumbnails/15.jpg)
Now
Lab!
15