You are on page 1of 26

Data using

Analytics
Introduction to R
INTRODUCTION TO R
R is a statistical programming language commonly used for statistical
analysis, data visualization, and other forms of data manipulation.

R Packages R Core R Studio

DICT Cordilleras
R STUDIO IDE

Environment
Source

Files/Plots/Packages
Control
DICT Cordilleras
Arithmetic

DICT Cordilleras
SPACES BETWEEN CHARACTERS
Spaces between characters do not affect the code. It’s a good practice to add a space between
characters to make it easier to read.

DICT Cordilleras
Order of Operations

DICT Cordilleras
Order of Operations

DICT Cordilleras
Using Multiple Parenthesis

DICT Cordilleras
Variables
In programming languages, we need to use various variables to store various
information. Variables are the reserved memory location to store values. As we
create a variable in our program, some space is reserved in memory.

DICT Cordilleras
Variables
In programming languages, we need to use various variables to store various
information. Variables are the reserved memory location to store values. As we
create a variable in our program, some space is reserved in memory.

DICT Cordilleras
Variables Naming Conventions
In programming languages, we need to use various variables to store various
information. Variables are the reserved memory location to store values. As we
create a variable in our program, some space is reserved in memory.

x 2Dave (can't start with a number)


Total total_score% (can't have characters other
.mean.avgs.set than dot (.) or underscore (_)
total_minus_input .3total_score (can start with (.), but not
userAverageScores followed by a number
Dave17 _total_score (can't start with _ )

DICT Cordilleras
PROBLEM SOLVING PROCESS
Tools
OBJECTIVE
Prepare breakfast for the family

PROCEDURE
prepare the pan
add a little oil to the pan
Containers and get 1 egg
Ingredients
break and put the egg in the
pan
put salt
cook for 1 minute
remove the egg from the pan
repeat process 5 more times
DICT Cordilleras serve the breakfast
Data Types and Data Structures

Data Data
Types Structures
DICT Cordilleras
Data Types

DICT Cordilleras
DATA 1 Vectors

STRUCTURES 2 Lists

3 Matrices

4 Arrays

5 Data Frames

6 Factors

DICT Cordilleras
Data Structures

DICT Cordilleras
Vector
In R, a sequence of elements which share the same data type is known as vector

Creating Vectors

1. Using the colon(:) operator

2. Using the seq() function

DICT Cordilleras
Vector
In R, a sequence of elements which share the same data type is known as vector

Creating Vectors

1. Using the c() function - combine

DICT Cordilleras
Vector
In R, a sequence of elements which share the same data type is known as vector

Creating Vectors

1. Using the c() function - combine

NOTE: c is variable
c() is the combine function

DICT Cordilleras
Vector
In R, a sequence of elements which share the same data type is known as vector

Accessing vector elements

Index number 5 not existing


DICT Cordilleras
Data Frame
Comprised of rows and columns, where elements of each column is of the same type

DICT Cordilleras
Data Frame
Comprised of rows and columns, where elements of each column is of the same type

Creating Data Frames Vectors as Columns

DICT Cordilleras
Data Frame
Comprised of rows and columns, where elements of each column is of the same type

Creating Data Frames

Import a CSV file into R

DICT Cordilleras
Data Frame
Comprised of rows and columns, where elements of each column is of the same type

Accessing Elements of a Data Frame

Returns items column as Vector

Access elements as vector


DICT Cordilleras
Data Frame
Comprised of rows and columns, where elements of each column is of the same type

Slicing the Data Frame

DICT Cordilleras
Next : Data Exploration

You might also like