1.1 Introduction To R Language 1
1.1 Introduction To R Language 1
Introduction to R Programming
for Data Science
Introduction to R Language 1
Objectives
• Explain what R language is and the purpose of R
• Download and Install R
• Learn general Issues in R
• Introduce R-Packages
3
Introduction to
R Programming for Data Science
4
Introduction to
R Programming for Data Science
2 3
1 4
5
Introduction to
R Programming for Data Science
6
What is R?
Software for Statistical Data Analysis
Based on S
Programming Environment
Interpreted Language
Data Storage, Analysis, Graphing
Free and Open Source Software
7
Obtaining R
Current Version: R-4.2.2
Comprehensive R Archive Network:
http://cran.r-project.org
Binary source codes
Windows executables
Compiled RPMs for Linux
8
Installing R
Binary (Windows/Linux): One step process
Starting R
9
General Issues in R
1. Unmatched parentheses, curly braces, square brackets or quotes
Solution
•Using RStudio a closing
parenthesis, curly brace, square
bracket or quotation mark will
automatically be written when
opening one
•Match all opening parentheses,
curly braces, square brackets and
quotation marks with their
closing counterparts
10
General Issues in R
2. Using a function that is not installed or loaded
Solution
Install the package (if it is not installed yet) and load it with
the install.packages() and library() functions, respectively:
11
General Issues in R
3. Typos in function, variable, dataset, object or package names
Solution
Make sure that
you correctly
spell all your
functions,
variables,
datasets, objects
and packages
12
General Issues in R
4. Missing, incorrect or misspelled arguments in functions
Most R functions require arguments
Solution
•Make sure to specify at least all compulsory arguments of the
function, and the correct ones
•If we do not know the arguments of a function, we can always check
the documentation with ?function_name or help(function_name)
13
General Issues in R
5. Wrong, inappropriate or inconsistent data types
Solution
Make sure to use the appropriate operation and type of analysis depending
on the variable(s) of interest. For example:
• for factor variables => compute frequencies and/or relative frequencies,
and draw barplots
• for quantitative continuous variables => compute the mean, median, etc.
and draw histograms, boxplots, etc.
• for logical variables, the mean, a frequency table and a barplot are
appropriate 14
General Issues in R
6. Misunderstanding between = and ==
Assignment in R can be done in three ways, from the most to the
least common:
<-, =, assign()
The second method, that is =, should not be confused with ==
15
General Issues in R
7 . Undefined columns selected
16
General Issues in R
8. Problem when importing or using the wrong data file
Solution
Specify the path to the folder where your dataset is located
17
R-Packages
R packages are a collection of R functions, complied code
and sample data. They are stored under a directory called
"library" in the R environment
20
R-Packages
• Check Available R Packages
o Get all packages currently loaded in the R environment
21
R-Packages
• Install a New Package
o Packages are added when they are needed for some specific purpose
o There are two ways to add new R packages:
o Installing directly from the CRAN directory
o Downloading the package to the local system and installing it
manually.
o Install directly from CRAN
22
R-Packages
• Install package manually
Go to the link R Packages to download the package needed. Save the
package as a .zip file in a suitable location in the local system .
23
Summary
•
Explain what R language is and the purpose of R
• Download and Install R
• Introduce R-Packages
• General Issues in R
24
Q&A
25