0% found this document useful (0 votes)
131 views19 pages

Introduction To R Programming

This document introduces R and RStudio. It discusses that R is an open-source programming language for statistical analysis and data science. RStudio is an integrated development environment for R that is available on Windows, Linux, and Mac OS. The document then provides steps for setting a working directory in R, creating and saving R script files, and executing entire R script files or portions of code using the Run or Source commands in RStudio.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views19 pages

Introduction To R Programming

This document introduces R and RStudio. It discusses that R is an open-source programming language for statistical analysis and data science. RStudio is an integrated development environment for R that is available on Windows, Linux, and Mac OS. The document then provides steps for setting a working directory in R, creating and saving R script files, and executing entire R script files or portions of code using the Run or Source commands in RStudio.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction to R

NPTEL NOC18-CS28
Data science for Engineers

In this lecture
 R and RStudio
 How to
◦ set the working directory
◦ create an R file and save it
◦ execute an R file
◦ execute pieces of code

R Basics NPTEL NOC18-CS28 2


Data science for Engineers

R
 Open source programming
language
 Statistical software and Data
analysis tool
 Interface
◦ Command line user interface
 Platforms
◦ Windows, Linux and Mac OS

R Basics NPTEL NOC18-CS28 3


Data science for Engineers

RStudio
 Integrated Development Environment
(IDE) for R
 Availability
◦ Open source
◦ Commercial
 Editions
◦ Desktop
◦ Server
 Platforms
◦ Windows, Linux and Mac OS

R Basics NPTEL NOC18-CS28 4


Data science for Engineers

A first look of RStudio

Environment/History

Files/Plots/Packages/Help

Console

R Basics NPTEL NOC18-CS28 5


Data science for Engineers

Set the working directory


Enter in the console : setwd( “directorypath” )

(OR)
To choose Working
directory
STEP 1: Choose a suitable location by clicking on the indicated icon

R Basics NPTEL NOC18-CS28 6


Data science for Engineers

Set the working directory


STEP 2: Once directory is chosen, select the more icon and choose “Set as Working Directory”

R Basics NPTEL NOC18-CS28 7


Data science for Engineers

RStudio

R Basics NPTEL NOC18-CS28 8


Data science for Engineers

Create an R file
“File” icon

R Basics NPTEL NOC18-CS28 9


Data science for Engineers

Create an R file
By clicking the icon “ ”below the toolbar

R Basics NPTEL NOC18-CS28 10


Data science for Engineers

RStudio with script file open

Scripts
Environment/History

Files/plots/packages/Help

Console

R Basics NPTEL NOC18-CS28 11


Data science for Engineers

Writing scripts

R Basics NPTEL NOC18-CS28 12


Data science for Engineers

Saving R script file

R Basics NPTEL NOC18-CS28 13


Data science for Engineers

Saving R script file

R Basics NPTEL NOC18-CS28 14


Data science for Engineers

Executing an R file

A) Press Run/ Ctrl + Enter

B) Press Source / Ctrl + Shift + S


Or
C) Press Ctrl + Shift + Enter (Source with echo)

Source will execute all commands in console


without displaying them where as source with
echo will execute and print automatically

R Basics NPTEL NOC18-CS28 15


Data science for Engineers

Executing an R file: Example

RESULT

R Basics NPTEL NOC18-CS28 16


Data science for Engineers

Execute pieces of code – Run

R Basics NPTEL NOC18-CS28 17


Data science for Engineers

Execute pieces of code – Run

Value of ‘a’ has changed but not ‘b’

R Basics NPTEL NOC18-CS28 18


Data science for Engineers

Executing R files – Summary


 Run can be used to execute
selected lines
 Source/ Source with echo is for a
whole file
 Advantages – using Run :
◦ troubleshooting/debugging
 Disadvantages – using Run :
◦ For large section, console will be over
populated and messy

R Basics NPTEL NOC18-CS28 19

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy