The Network Simulator NS-2 & SCTP Module Student : Kuo-Lun Lu Advisor : Dr. Jen-Yi Pan.
Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen...
Transcript of Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen...
![Page 1: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/1.jpg)
Getting Started with R
Tony Yao-Jen Kuo
![Page 2: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/2.jpg)
Getting Started
![Page 3: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/3.jpg)
The characteristics of R
I Comparing to Matlab, SAS, SPSS: FreeI Comparing to Julia: Larger communityI Functional Programming
![Page 4: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/4.jpg)
R in one sentence
Applying functions to objects.
![Page 5: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/5.jpg)
R: core of computationI Download from https://cran.r-project.org/
Figure 1:
![Page 6: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/6.jpg)
RStudio: the IDE
I Download fromhttps://www.rstudio.com/products/rstudio/download
![Page 7: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/7.jpg)
Interface of RStudio
![Page 8: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/8.jpg)
Four blocks
I ScriptI ConsoleI EnvironmentI Multi-functional
![Page 9: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/9.jpg)
Console tricks
I Using Ctrl + L for clearingI Using Up and Down arrow checking executed scripts
![Page 10: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/10.jpg)
Keyboard shortcuts
I Using Alt + Shift + K for shortcuts
![Page 11: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/11.jpg)
Quickstart
![Page 12: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/12.jpg)
Using <- for assignment
I = is OKAY, but <- is more commonI Using Alt + - to get <-
![Page 13: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/13.jpg)
Using # for comments
# Declaring objects
# Declaring function
![Page 14: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/14.jpg)
Assignment in action
# Declaring objectsmy_favorite_star <- "Tom Cruise"my_lucky_number <- 24r_is_easy <- TRUE
# Declaring functionsay_hello <- function(){
return("Hello R!")}
![Page 15: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/15.jpg)
Printing objects or calling function
# Printing objectsmy_favorite_starmy_lucky_numberr_is_easy
# Calling functionsay_hello()
## [1] "Tom Cruise"## [1] 24## [1] TRUE## [1] "Hello R!"
![Page 16: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/16.jpg)
Using rm() to remove objects
rm(r_is_easy)r_is_easy # Error
![Page 17: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/17.jpg)
Why is R Console showing +?
I The reason is that R is still expecting inputs from us
my_favorite_player <- "Steve Nash
say_hello <- function(){return("Hello R!")
help(print
![Page 18: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/18.jpg)
2 ways to solve it
1. Complete your inputs2. ESC
![Page 19: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/19.jpg)
Install packages
I install.pacakges()I Do it once
![Page 20: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/20.jpg)
Library packages
I library()I Do it every time
![Page 21: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/21.jpg)
Useful functions
![Page 22: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/22.jpg)
Function to query functions or data
help(print) # ?printhelp(cars) # ?cars
![Page 23: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/23.jpg)
Function to show relative informationsessionInfo()
## R version 3.4.4 (2018-03-15)## Platform: x86_64-apple-darwin15.6.0 (64-bit)## Running under: macOS High Sierra 10.13.6#### Matrix products: default## BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib## LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib#### locale:## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8#### attached base packages:## [1] stats graphics grDevices utils datasets methods base#### loaded via a namespace (and not attached):## [1] compiler_3.4.4 backports_1.1.2 magrittr_1.5 rprojroot_1.3-2## [5] tools_3.4.4 htmltools_0.3.6 yaml_2.1.19 Rcpp_0.12.16## [9] stringi_1.2.4 rmarkdown_1.9 knitr_1.20 stringr_1.3.1## [13] digest_0.6.15 evaluate_0.11
![Page 24: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/24.jpg)
Function to get locale
Sys.getlocale()
## [1] "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8"
![Page 25: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/25.jpg)
Function to get current working directory
getwd()
## [1] "/Users/kuoyaojen/r_programming"
![Page 26: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/26.jpg)
Function to set working directory
I Always use forward slash when declaring pathI Back slash has other functionalities, such as escape, Unicode. . .I Try not to use non-English username
setwd("/Users/USERNAME/Desktop") # MacOS desktopsetwd("C:/Users/USERNAME/Desktop") # Windows desktop
![Page 27: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/27.jpg)
Function to quit RStudio
I Not saving workspace image is recommended
q()
![Page 28: Getting Started with R - Yao-Jen Kuo · 2019. 3. 6. · Getting Started with R Author: Tony Yao-Jen Kuo Created Date: 9/1/2018 11:59:30 AM ...](https://reader033.fdocuments.net/reader033/viewer/2022060903/609f0051d012cd5d3a4a0c2c/html5/thumbnails/28.jpg)
Common learning path for programming
I Installation of compiler or interpreterI Choosing a friendly IDEI QuickstartI Variable typeI Control flowI Data structureI IterationI FunctionI (Optional) ClassI (Optional) Package