0% found this document useful (0 votes)
38 views14 pages

Data Science in Process Engineering: Introduction To R

R is an open-source programming language used for statistical analysis and graphics. It allows users to analyze data using over 10,000 pre-defined functions. This document introduces R and RStudio, the basic data types in R like numeric, integer, logical, and character, and common R objects like vectors, matrices, data frames, and lists to store and organize data. The key commands for assigning values to variables and accessing elements within objects are also covered.

Uploaded by

anas daham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views14 pages

Data Science in Process Engineering: Introduction To R

R is an open-source programming language used for statistical analysis and graphics. It allows users to analyze data using over 10,000 pre-defined functions. This document introduces R and RStudio, the basic data types in R like numeric, integer, logical, and character, and common R objects like vectors, matrices, data frames, and lists to store and organize data. The key commands for assigning values to variables and accessing elements within objects are also covered.

Uploaded by

anas daham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Data Science in

Process Engineering
Introduction to R
Learning objectives

• Know what is R and how it works?


• Learn basics of working with data in R.
• Get familiar with basic commands/functions.
• Learn how to do basic analysis on any dataset
and be able to create basic charts
What is R?
Why we use it?

• It’s a tool : Open-Source, cross platform, free programming


language designed to build statistical solutions.
• Powerful : Gives access to CRAN repository containing over 10,000
packages with pre-defined functions for almost every purpose
• Stays Relevant : Constantly being updated by users ( Scientists,
Statisticians, Researchers, Engineers Students!)
• More: Makes beautiful graphs, can create custom functions or
modify existing ones, can be integrated into many environments
and platforms such as MATLAB etc.
Installing R

• Can be downloaded for free from http://


www.r-project.org/
• Download the version compatible with your OS.
• Simple/Standard installation process
Installing R -Studio

• Can be downloaded for free from: https://


www.rstudio.com/products/rstudio/download/
• Download the free version compatible with your OS
• R needs to be installed before installing R- Studio
R-Studio UI

Global Environment
Write Your See your datasets here
Code Here!

See your files,


graphs, help
Console - see documentation
your code run and installed
here packages here
R Commands

• AssignmentsE.g.: x = 1, or x <- 1
• Functions E.g.: print(“Hello World”)
• Computations E.g.: 17 + 3 ; x + 5
• Mix E.g.: y = sqrt(16); y = 15 + 5
• Assignment queries will update objects in your R environment
• Queries without assignment, as well as ‘call’ of R objects will
either generate an output in the console, or in the plot tab
Variable Assignment

• A basic construct in programming is "variable“


• A variable allows you to store a piece of data (‘datum’,
e.g. 6, ‘Hello’, etc.. ) or several pieces of data of a
common type, and assign them a unique name
• You can then later ‘call’ this variable's name to easily
access the value(s) that is/are stored within this variable.
• Careful, R is case sensitive: The variables ‘x’ and ‘X’ can
coexist in R environment and have different values.
Basic Data types

• R works with numerous data types.


• The most common types are:
– Decimals values like 3.5, called 'numeric’
– Natural numbers like 3 are called 'integers'. Integers are
also numeric
– Boolean variables (TRUE or FALSE) are classified as
‘logical’
– Text (or string) values are classified as 'character’
Basic data types

• Categorical variables are called ‘factors’. They have a


finite and defined set of values they can take (e.g.
eye_color can take have a value contained in {‘blue’,
‘green’, ’brown’, ‘black’})
• Other variables can contain time data such as dates,
day of the week, hours, minutes, etc..
R Objects: Vectors

• To assign multiple values to a variable, we can use an R object


called a ‘vector’
• A vector is a sequence/collection of data elements of the same
basic type. Members in a vector are officially called components.
For Example: my_vector = c(14,26,38,30)
• To access a specific element in the vector, we simply need to call
variable_name[i], ‘i’ being the element’s position in the vector.
For example: vect[3] would return 38
R Objects: Matrices

• A matrix is a sequence/collection of data elements of the same basic type


arranged in a two-dimensional rectangular layout.

• Being a 2-dimensional object, in order to obtain a specific value within the


matrix, 2 coordinates needs to be entered. For example: my_matrix[i,j] would
return the element on the ith row, in the jth column

• my_matrix[i,] would return the entire ith row

• my_matrix[,j] would return the entire jth column


R Objects: Data
Frames
• A data frame is used for storing data tables.
• It is a list of vectors of equal length.
• Unlike matrices, it can gather vectors containing
different basic types
• Selection of specific elements in data frames works the
same way as for matrices.
• For example: my_dataframe[i,j] would return the
element on the ith row, in the jth column
R Objects: Lists

• A list in R allows you to gather a variety of objects under one


name (that is, the name of the list) in anordered way.
• These objects can be matrices, vectors, data frames, even
other lists, etc.
• It is not even required that these objects are related to each
other.
• To access the i object in the list, write my_list[[i]]
th

• If you want to access a variable in the i object in the list,


th

write my_list[[i]] [variable coordinates].

You might also like