Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
52 views11 pages

Lec2 - Introduction To R

This document provides an introduction to basic R functions such as adding comments, clearing the environment and console, and saving the R workspace. It explains how to add single-line and multi-line comments in R. It also demonstrates how to clear the console using Ctrl+L, clear variables from the environment using rm(), and confirm clearing variables. Finally, it discusses automatically saving the workspace and manually saving and loading the entire workspace or individual variables to a file.

Uploaded by

Shashank Gautam
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)
52 views11 pages

Lec2 - Introduction To R

This document provides an introduction to basic R functions such as adding comments, clearing the environment and console, and saving the R workspace. It explains how to add single-line and multi-line comments in R. It also demonstrates how to clear the console using Ctrl+L, clear variables from the environment using rm(), and confirm clearing variables. Finally, it discusses automatically saving the workspace and manually saving and loading the entire workspace or individual variables to a file.

Uploaded by

Shashank Gautam
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/ 11

Introduction to R

NPTEL NOC18-CS28
Data science for Engineers

In this lecture
 How to
◦ add comments
◦ clear the environment
◦ saving the workspace

R Basics NPTEL NOC18-CS28 2


Data science for Engineers

Add comments –single line


For single line comment, insert ‘#’ at the start of the line

R Basics NPTEL NOC18-CS28 3


Data science for Engineers

Add comments –Multiple lines


Two ways:
1) Select multiple lines using
cursor, then press “Ctrl +
Shift + C”
(OR)

2) Select multiple lines


using cursor, click on
“Code” in menu and select
“Comment/Uncomment
lines”
R Basics NPTEL NOC18-CS28 4
Data science for Engineers

Clear the console


“control +L”

Ctlr + L

R Basics NPTEL NOC18-CS28 5


Data science for Engineers

Clear the environment –rm()


Single variable: Enter in console/R script : rm(variable)

All variables: Enter in console/R script : rm(list=ls())

OR

R Basics NPTEL NOC18-CS28 6


Data science for Engineers

Confirmation dialog

R Basics NPTEL NOC18-CS28 7


Data science for Engineers

Empty environment

R Basics NPTEL NOC18-CS28 8


Data science for Engineers

Saving data from workspace


Workspace data
 Workspace information is temporary
 Is not retained after the session
◦ If you close the R-session
◦ If you restart the computer

R Basics NPTEL NOC18-CS28 9


Data science for Engineers

Automatic option

R Basics NPTEL NOC18-CS28 10


Data science for Engineers

Manual saving
 Can be permanently saved in a file – save command
 Can be reloaded for future sessions – load command

# Example code
save(a, file=“sess1.Rdata”) # to save a single variable ‘a’
# to save a full workspace with specified file name
save(list=ls(all.names=TRUE), file=“sess1.Rdata”)
save.image() # short cut function to save whole workspace
load(file=“sess1.Rdata”) # to load saved workspace

R Basics NPTEL NOC18-CS28 11

You might also like