Professional Documents
Culture Documents
Intro2R Wk1
Intro2R Wk1
Funding
• U.S. Department of State awards SMLAQM19CA2361
Partnerships
• The U.S Embassy in Bangladesh and U.S Consulate General, Kolkata.
Academic collaborations
• Dhaka University and Bose Institute, Kolkata.
Introduction to R
Subjects to be covered
Experience needed
Experience with data in excel or another spreadsheet program. Basic statistics.
Required
Access to an internet connected computer with R installed. See https://cran.r-project.org for
download and installation instructions.
Materials
Presentation slides and R code can be found at.
https://drive.google.com/drive/folders/1UmMo968xAO-cQiUCx6HMNEZtTtExUQP3?usp=sharing
R Language
Why R?
• Most popular language for data science.
• Open source.
• Large community.
• More focused on statistics and data exploration than
Python.
• Python is better for long-term production and
deployment of data pipes etc.
R Background
• Named after the first initial of the R authors and as a play on the name of S
language.
R - Some basic questions
How do I install R?
R IDE and R Studio ?
help? Exporting data from R ?
Importing data into R?
• Windows R FAQ is at
https://cran.r-project.org/bin/windows/base/rw-FAQ.R-
4.2.1.html
R Windows Users
Entering Commands
R is a case sensitive command line driven program. The user enters commands at the
prompt > each command is executed one at a time.
This command runs the function “mean” on the data contained in object “x” .
Operators
Arithmetic Logical
Operator Description Operator Description
+ addition > greater than
- subtraction
>= greater than or equal to
* multiplication
== exactly equal to
/ division
^ or ** exponentiation != not equal to
R Assignment Operator
Assignment “<- “
e.g. a <- mean(x) # applies the mean function to x and creates a new object called “a” to hold
answer
R session concepts
R session
Workspace
R session concepts
Workspace Default workspace loads on startup
Working directory The starting directory , to search for folders, data etc.
R session concepts
R GUI
Menu bar Preferences, graphics devices, package installation + management etc.
Document window Text editor for building and running scripts ( series of commands).
R session concepts
R command line R can be run without the GUI from a CLE terminal
Install a package
• Got to the Packages & Data menu
and select Package Installer.
Install a package
• The first time you install a package a large
number of other dependent packages may
also be installed.
Package Manager
detach(package:openair ,unload=TRUE)
search() # check that package is detached.
R GUI
• For example
Functions Dependent
• R packages often contain data for packages
example use or for the package Data
functions. R package structure
Wk 1.1
a. Install the following packages using the package manager.
tidyverse
lubridate
dplyr
ggplot2
Openair
b. Attach and detach the packages using the package manager and
commands
WK 1 Exercises
Wk 1.2
a. Find your working directory using the misc menu and the command.
getwd()
https://drive.google.com/drive/folders/1K86en-JdVS5nHdMuGPlaChO1
mKMvs0Rx?usp=sharing
Wk 1.3
a. In the console type command:
source("tsi_concat_dat.r")
This command will attach packages and load the tsi_concat_dat function.
If that fails go to R File menu, select source file and find tsi_concat_dat.r.
WK
WK11Exercises
Exercises
Wk 1.4 R Commands
https://www.rstudio.com/products/rstudio/download/